Re:Real world feedback from a Java dev using Scala
by masklinn on Tuesday May 01, 2012 @06:46PM
(#3916704)
Re. SSA, I used to use it by default in Java when I still worked with that language, you don't have to switch to java to have it. Although it is significantly more verbose than in Scala (let alone in e.g. Erlang). Even for the shape you show here it can be done, Java has basic initialization guarantees so you can write:
final int i;
if (condition) {
// logic
i = 1;
} else {
i = 0;
}
and javac will produce an error if you forget the second branch of the conditional as this would allow an uninitialized `i`.
Although for clarity's sake I'd probably invert the condition so the "default" case is easier to see.
That also works for instance members, javac will allow setting them in a constructor or an initialization block, and will verify that they are set (and not set twice so you can't set the member in a constructor and an initialization block)
Although for clarity's sake I'd probably invert the condition so the "default" case is easier to see.
That also works for instance members, javac will allow setting them in a constructor or an initialization block, and will verify that they are set (and not set twice so you can't set the member in a constructor and an initialization block)