I am a consultant and the author of 24 books on artificial intelligence and the semantic web. I use this blog to share ideas and code snippets using my favorite languages: Clojure, Java, Haskell, Common Lisp, and Ruby.

Sunday, May 31, 2009

Scala really is a "better Java"

I have been so busy this year that I have slacked off on fully getting up to speed on Scala (and Haskell, for that mater). A few people have been working on a Sinatra clone in Scala. (Sinatra is a very nice minimalist Ruby web framework that I like a lot.) I grabbed a version of the Step project off the web today and I just had some time to play with it.

You could not really write something like Step in Java without writing an interpreter. With Scala, you can add syntactic sugar similarly to Ruby. Step nicely emulates parts of Sinatra; here is a code block wrapped to handle an HTTP GET request mapped to the route "/form":

Groovy has become a popular language, but if I want a slow scripting language, I prefer Ruby (or JRuby on the JVM).

Scala has a huge advantage over Groovy and JRuby: very good runtime performance (almost as good as Java). Check out language benchmarks comparing these three languages. Ruby has become my default programming language, but I do still go back to Java (or Common Lisp) when I need good runtime performance.

I think if you take care of java reflection calls in clojure is faster than jruby or ruby, it's homoiconic (code-as-data), it have STM and in general it's more lispy (including macros which allows the compiler to be extended by user code) I think clojure is a step forward (or back if you look at its 50's syntax) from scala or ruby

Jim: Java coding is a little painful, compared to most other languages I use. But, the JVM plaform is great - thus my interest in Scala: very close to Java performance with excellent language features. Also, a hike would have been good!

Javier: Yes, Clojure is somewhat faster than JRuby. BTW, the benchmark you linked to between Clojure and Scala is more than a little bogus: Scala should be compiled (to get tail recursion optimization). Also, the benchmark itself does not seem very 'real world'. The developer of Clozure released (many years ago) an open source bridge between Java and LispWorks - that was very cool. I tink that Clojure is a great idea and implementation - it is just that if I use a Lisp language, I want very good runtime performance (I use SBCL, Franz Lisp, and Gambit-C Scheme).

Hi Mark, I'm Alan, one of the Step developers. Thanks for trying it out, and for your kind praise. I've been working with Scala for a few months now, and it has yet to rub me wrong.

Speaking to the other comments on this page, I think that taken together as interoperable languages on a common platform, JRuby, Groovy, Clojure, Scala, and Java represent a unified and powerful (maybe even unprecedented) set of tools for the engineer.

So while each has its upsides and downsides, they all share the common ability to work nearly seamlessly with one another. I've been experimenting with a JRuby on Rails/ScalaQuery project that has been surprisingly easy to get off the ground. This, I think, is just awesome.

Thanks again for checking out Step, and I've really enjoyed browsing your posts.