Monday, August 24, 2009
 

Java programmers: you must read these two books

Recently, there has been a lot of hype around the idea of using different languages for programming the JVM. Many languages are available, as you probably know. However, I think two of these languages are specifically worth taking a look at because they approach the problem quite differently. These languages are Scala and Clojure.

So, what is the problem? The problem is, in my opinion, that the Java language (not the JVM) has stagnated. When Java was created, one of the primary goals was a significant simplification compared to C++. And I would argue, that this goal was reached. Java has deserved it's success. However, the landscape has changed over the last couple of years and Java did not evolve. Example areas include concurrency, functional programming, metaprogramming (internal) DSLs and type systems. As a consequence, alternatives languages flourished.

It is interesting to see how Clojure and Scala address this challenge very (although not completely) differently. I'd say the only thing they have in common is their emphasis on functional programming.

So let us look at some of the differences:

Typing: Scala is strongly typed, even more strongly than Java, but it comes with a sophisticated type inferencer to make sure the type system does not get in your way. Clojure on the other hand uses dynamic typing (duck typing, specifically), like so many of the "newer" languages. Consequently, Scala has a very sophisticated compiler, whereas Clojure emphasizes much more the runtime system.

Concurrency: Scala uses the actor model. Actors are lightweight threads that communicate by message passing. Clojure mainly relies on immutable data structures and pure functions, but it also comes with a software transactional memory facility for managing shared state without requiring developers to manually manage locks.

Syntax: Scala's syntax is in the tradition of Java. Although it reduces noise significantly (thanks to type inference and many other useful conventions) it is still driven by keywords and different special symbols. Clojure on the other hand, in the tradition of Lisp, basically treats everything as a list. I have not yet made up my mind as to which syntactic style I prefer. My stomach tells me I prefer Scala style. However, I do recognize that the simplicity orthogonality of Lisp like syntax provides for some very powerful facilities (macros)

Extensibility and Metaprogramming: Both languages emphasize extensibility in the sense that you should be able to use libraries to provide powerful functionality, which ideally looks like as if it would be built into the language. As usual in Lisps, closure provides a macro system that supports the definition of almost arbitrary special forms (as long as they still look like a list, syntactically - that's the catch, of course). In Scala, by being able to avoid the dot operator, parentheses and semicolons and through clever use of functions, you can achieve some of the same goals (there is also a compiler plug-in framework).

So, why am I talking about this, and why thus the title of this post talk about books?

I would suggest that every self-respecting Java programmer has to inform themselves about these two languages. Even if you will never use them, you should take a look to understand how the same problem can be solved in different ways, and how languages on the JVM can evolve (both provide extremely good interoperability with Java the language, by the way). It's a matter of looking beyond your own nose.

To do so, I suggest you read the following two books. Both are reasonably short, very well written, and emphasize the important issues:

Programming Scala by Venkat Subramaniam and Programming Clojure by Stuart Halloway
 
Comments:
I would suggest learning about Scala and Groovy. As the static and dynamic approach toward “better Java”. Especially that imho Groovy has the smallest learning curve and extensive syntax that can be Java compatible or quite different (dots, semicolons, AST macros). However I have never used Lisp, so maybe I will check Clojure someday ;)
 
I specifically did not recommend Groovy. Not because I don't like it or because it think it's not useful, but because I think most people already know it, and because Clojure is much more different from all the rest, which is why I think it's a good thing to look at.

From a "what's useful in practice" perspective I would think that more people will use Groovy and not Clojure.
 
+1 to the suggestion of learning these languages. As you know, I'm more into Lisp, so I probably lean as much (or as little) to Scala as you do to Clojure :-)

One thing worth pointing out: Clojure has Agents, which are somewhat similar to Actors.
 
Post a Comment

<< Home

back to voelter.de

ABOUT ME
This is Markus Voelter's Blog. It is not intended as a replacement for my regular web site, but rather as a companion that contains ideas, thoughts and loose ends.

ARCHIVES
December 2005 / January 2006 / February 2006 / March 2006 / April 2006 / May 2006 / June 2006 / July 2006 / August 2006 / September 2006 / October 2006 / November 2006 / December 2006 / February 2007 / March 2007 / April 2007 / May 2007 / June 2007 / July 2007 / September 2007 / October 2007 / November 2007 / December 2007 / January 2008 / February 2008 / March 2008 / April 2008 / May 2008 / June 2008 / July 2008 / August 2008 / September 2008 / October 2008 / November 2008 / December 2008 / January 2009 / February 2009 / March 2009 / April 2009 / May 2009 / June 2009 / July 2009 / August 2009 / September 2009 / October 2009 / November 2009 / December 2009 / January 2010 / February 2010 / April 2010 / May 2010 / June 2010 / July 2010 / August 2010 / September 2010 / October 2010 / November 2010 / December 2010 / January 2011 / March 2011 / April 2011 / May 2011 / June 2011 / July 2011 / October 2011 / November 2011 / December 2011 / January 2012 / February 2012 / October 2012 / January 2013 /

FEED
You can get an atom feed for this blog.