Week 4: Scala

September 7th, 2013

It’s a while ago since I last wrote some Scala code so this week was fun picking it back up.

Scala is not a full object-oriented language nor a functional language, but it supports both paradigms. In fact, the intension of Scala’s creator, Martin Odersky, was to form a bridge between the object-oriented and functional paradigms, much like C++ was a bridge between the procedural and object-oriented paradigms.

Scala gets the character of Edward Scissorhands: often awkward, sometimes amazing, but always a unique expression. This is absolutely true for Scala, with it’s academic-like syntax.

Scala fits the role of being a bridge like a glove. It has a strong affinity with Java; it runs on the Java virtual machine, it allows you to call Java libraries directly, and as mentioned before, it supports the ideas of object orientation.

Personally I find its static typing still pretty intrusive and still found myself adding redundant type information just to satisfy the compiler. Also the Scala language looks much more complicated because of its static typing. But it definitely eases the static typing burden of the Java language. Because the syntax is simpler and the code is less polluted with type information, I also found it easier to express ideas in Scala than in Java.

On the up-side, Scala’s actor model is a welcome improvement in concurrent programming. Combined with immutable (shared) state it makes it much more easy to reason about concurrency. Scala is also very powerful for creating DSLs, and its built-in XML support is a great example of that.

My solutions to the more interesting exercises in the book (a Tic-tac-toe game and a text censor trait) are available in the 7-languages-in-7-weeks repository on my Github profile. For day 3 I didn’t include the exercise as it was rather trivial.

I do believe that there’s a future for Scala. Its support for object-orientation makes it easier to get started for programmers who don’t know functional programming. And for programmers who do understand a bit about functional programming, Scala has excellent support for that too - especially with the Scalaz extension.

I would like to get back to Scala and definitely prefer it over Java. For now this is where I leave Scala and focus on the next language: Erlang.