One of the questions now trending in the Java world shows a hesitation to buy into a technology that might turn out to be a passing fad: should I learn Scala or should I learn Clojure?
Especially when it comes to a learning curve that entails a paradigm shift and a reassessment of one’s dedication to object orientation, nobody wants to put in the time and then find that his new language of choice lacks street value or practical relevance.
That’s the conventional sentiment behind the question, but perhaps the premise of that question is itself faulty. The premise is that the time invested in picking up an “impractical” or trendy language is actually time wasted.
But why suppose so? Taking an academic interest in non-commercial, enlightening languages may yield indirect benefits.
The recent volume from Bruce Tate, Seven Languages in Seven Weeks, explores precisely this issue by demonstrating what can be learned from a diverse handful of languages and by speculating about how those lessons might improve a programmer’s practice.
Similar in intent but narrower in scope is the forthcoming volume by Ben Evans and Martijn Verburg, The Well Grounded Java Developer: Java 7 and Polyglot Programming on the JVM.
On the basis of this approach to the issue, it would make sense to learn both Scala and Clojure (as well as Prolog, Io, and a few others). But that leaves open the issue of priorities. Which has the better bang/buck ratio? I think the answer to that question can be derived in many ways, but maybe the simplest is to look at goals.
Clojure and Scala both provide support for functional idioms on the JVM. Clojure aims to be a relatively pure Lisp, while Scala seems to be a pragmatic hybrid that includes all the desiderata for which people frustrated with Java’s limitations have yearned. Clojure is simple and Zen; Scala is complex and heady. Clojure seems to want to do one thing well; Scala seems to want to do all things well enough. (But see this Yegge/Clojure slapfight including the follow-on page of posts.)
Perhaps this is a mischaracterization of one, of both, or even of the issue. Perhaps there’s a better set of metaphors to capture the essential difference between these two. Odersky sees room for both, and regards them as complementary. If you know a better way to boil down the distinction, share it in the comments!
My surplus attention right now is going to Clojure rather than to Scala, and the reason goes all the way back to a now famous article that Paul Graham wrote in 2002: Beating the Averages. There, Graham points back to something that Eric Raymond had previously written:
Lisp is worth learning for the profound enlightenment experience you will have when you finally get it; that experience will make you a better programmer for the rest of your days, even if you never actually use Lisp itself a lot.
Graham’s question is why you wouldn’t “actually use Lisp itself” if indeed its acquisition is so profoundly enlightening. “So if Lisp makes you a better programmer, like he says, why wouldn’t you want to use it?” Graham proceeds to explain how he and a partner did go all in on Lisp and thereby achieve a competitive advantage in the early years of web development. Along the way, Graham presents what he calls the Blub Paradox. This is the most well known part of the article:
Programmers get very attached to their favorite languages, and I don’t want to hurt anyone’s feelings, so to explain this point I’m going to use a hypothetical language called Blub. Blub falls right in the middle of the abstractness continuum. It is not the most powerful language, but it is more powerful than Cobol or machine language.
And in fact, our hypothetical Blub programmer wouldn’t use either of them. Of course he wouldn’t program in machine language. That’s what compilers are for. And as for Cobol, he doesn’t know how anyone can get anything done with it. It doesn’t even have x (Blub feature of your choice).
As long as our hypothetical Blub programmer is looking down the power continuum, he knows he’s looking down. Languages less powerful than Blub are obviously less powerful, because they’re missing some feature he’s used to. But when our hypothetical Blub programmer looks in the other direction, up the power continuum, he doesn’t realize he’s looking up. What he sees are merely weird languages. He probably considers them about equivalent in power to Blub, but with all this other hairy stuff thrown in as well. Blub is good enough for him, because he thinks in Blub.
This is Plato’s Cave, of course, and if you’ve spent a long time thinking in Blub and modeling the world in nouns, Graham maintains, then it’s hard to tell when you’re looking up at greater power rather than down at something weird and troubling.
If you haven’t read Graham’s article, you should go read the whole thing. It’s a classic. In the meantime, I’ll spoil his punch line for you: “Lisp is so great not because of some magic quality visible only to devotees, but because it is simply the most powerful language available.” That‘s why I find Clojure more exciting than some of the other newly fashionable JVM languages. It’s as expressive as a language can be, or a near approximation of that ideal, and I want some of that in the worlds I create in Java.