Getting Started with Scala

Scala IDE Worksheet

Scala IDE Worksheet

Martin Odersky over at the EPFL in Lausanne, Switzerland, has recently started the first offering of his course Functional Programming Principles in Scala on Coursera. It’s a seven-week long course, with weekly videos and programming assignments. I like it so far, as all the others from Coursera.

I do have some experience with functional programming – Haskell and Clojure to be specific. But I have to say, I like Scala better than both of them. Here’s why.

Scala and Clojure both have the advantage of being closely associated with the JVM; something that Haskell does not enjoy – which makes it less attractive for professional development. Furthermore, between Scala and Clojure, Clojure belongs to the Lisp family, and requires the use of an infix notation and lots of parentheses – while Scala does not.

Scala feels like a semicolon-less Java, and much much less verbose than the notoriously verbose Java. Java functions are directly callable from within Scala code. The Scala IDE, which is a stripped down Eclipse Indigo optimized for Scala, contains a distribution of Scala and works well. It comes with the Scala Worksheets (see attached figure for an example), which are like a REPL but better. You write your expressions, press ‘Save’, and voilà, the expressions are evaluated for you. I mean how neat is that?

With all this praise, there has to be some nitpicking as well, to keep things balanced in the world. I am not too fond of sbt, the Scala Simple Build Tool, that the course requires to be used for submitting the assignments. I am not knowledgeable enough to conjecture whether it is necessary or whether there could have been a simpler way. My problem with sbt is that every time you run it in a directory for the first time, it appears to download the world from the Internet, before it can start. Then, you have to type console in it to start the Scala interpreter. Given that the IDE already comes pre-equipped with a distribution of Scala, and the Worksheets are already a REPL, and there’s another version available from the official Website of the language, sbt just manages to come in and confuse the heck out of me. Maybe as I delve deeper into the language things will change and I will understand better.

As far as the language itself is concerned though, it is pure gold. To add to all the qualities listed above, going parallel with Scala is apparently as simple as adding a .par to any variable or object you create, and it’s easy to use Actors to manage more complicated parallel tasks. I cannot wait to learn more and get my hands dirty. Happy Scala-ing!

PS: Update: I’ve played with Eclipse (the Scala IDE) for a few days now and it has crashed on me several times. According to the gentlefolk over on StackOverflow, it seems to be a universally known problem. I came across a supposed bugfix which I tried, and then there was an update for the IDE as well, but none of that changed much. Further according to StackOverflow and this post here, apparently the way to go is IntelliJ IDEA with the Scala plugin. Whatever may be, for now I am sticking with Sublime Text 2 (since Vim by default does not recognize Scala) and SBT as the build/ test tool. I am also using the Scala version from the official Website for smaller stuff. Nothing is as snappy and awesome as the Scala Worksheets though in the IDE. Hopefully some future update will fix the problem.

Advertisements

One thought on “Getting Started with Scala

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s