Monday, August 17, 2009

My first impressions of the Scala programming language

update: The bug I describe below has since been fixed

Is Scala the new Java? I'd bet money on it for two reasons. First, Scala excels at several things that are not available in Java. The type system and closures have effectively grabbed the attention of language enthusiasts and fad followers. But to replace an institution like Java you need more. You need the average Joe to vote for you. This is the second reason: the cost of switching is low. Java developers won't have trouble with a transition like this. Idiomatic Scala might take a little effort ... but at a bare minimum, there is a one to one conceptual match up across the two languages. I dusted off a Java applet and ported it to Scala, see for yourself.

After playing with Scala a little bit I found my first problem with it. I could not have picked a worse way to get my feet wet. I'm not fond of applets but I had one laying around and thought I'd make things interesting by porting it. Then I fired up my web server and browser to find that my applet no longer worked. After a little while I traced the failure to a class loader problem in the browser. It turns out that everything that passes through scalac has a dependency on scala.ScalaObject and a host of other things in the Scala runtime. This means my applet gains 3.5 MB . Not a show stopper, but I think it's safe to say this is one thing Scala will not excel at.

And finally, I have no idea what's wrong with scala.collection.mutable.PriorityQueue . This REPL session says it all ...
scala> val q = new scala.collection.mutable.PriorityQueue[Int]
q: scala.collection.mutable.PriorityQueue[Int] = PriorityQueue()
scala> q.isEmpty
res0: Boolean = true
scala> q.size
res1: Int = 1     <- This has got to be a bug?

4 comments:

matthiaswessendorf said...

Nice post, thanks!
I hope you are doing fine. How is Chicago ?

Alan said...

Also don't forget about akka library if you need to write applications with parallelism. I prefer to mix scala, clojure and jython in my projects - each of them has some unique features.

ilya said...

Weird. In 2.8 this seems fixed. Also, doing q.toList.size gives correct result.

Not Dennis Byrne said...

@ilya ... yeah they fixed it for 2.8.