|
![](/i/fill.gif) |
On 17/04/2012 08:51 PM, Warp wrote:
> Invisible<voi### [at] dev null> wrote:
>> I'm still a bit baffled that this is a valid thing to do, however...
>
> There's some baggage from C that would have better been dropped, but
> as you may know, backwards compatibility can be a real b***h sometimes...
Don't we all know it. ;-)
(Haskell isn't as ancient as C, so fortunately it has much less of this.
It /does/ have it, however...)
> It can be argued using the same logic as with uninitialized variables,
> though: There are situations where execution never reaches the end of the
> function, and hence having a 'return' statement there would be useless.
Sure. But like I said, the Java compiler seems to detect this. If
doesn't just look at a function and say "does it contain a return
statement somewhere?" It actually statically analyses every possible
flow of control, and checks that every individual one ends with a return
(or throws an exception, which is also a valid way to terminate a function).
Of course, it's not perfect. Plausibly you could have if branches such
that a particular sequence of branches is impossible due to the
conditions in those branches, but the compiler wouldn't "see" that and
would still insist that you have a branch that doesn't terminate
properly. But I haven't seen that happen yet.
Post a reply to this message
|
![](/i/fill.gif) |