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