back

by wiradikusuma·14y ago·view on hn ↗
I'm in the same shoes with OP. Here's how my Scala skill progresses:

In the beginning, I wrote Scala "the Java way", sans semi-colons. Then I omit dots and parenthesis whenever possible (foo.do(bar) -> foo do bar). Then I learn to use immutable declaration (var -> val) and learn that expressions like this:

  var i = 0
  if (something) {
    // Additional logic
    i = 1
  }
Can be made immutable like this:

  val i = {
    if (something) {
      // Additional logic
      1
    } else 0
  }
Then I try to make use its functional goodies like map and fold, and so on. I use IntelliJ with Scala and JRebel (free for Scala!) plugin. JRebel allows you to "hot reload" Scala classes to avoid server restarts.

I admit I'm a frequent lurker in SO when using Scala, as its API doc sucks, and I also dislike its integration with Java, although it's not Scala's fault. For API doc, I think it'd be better if it has examples, which reminds me of ActionScript API docs.

1 comments
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)

s/switch to java/switch to scala/ of course.