Hacker News new | ask | show | jobs
Which one should I learn? Scala or Clojure
10 points by khichi 5292 days ago
In the long run, probably I will learn both. But which will give better ROI? Some parameters are:

> ease of learning > tools available > ease of integration with Java > libraries available

6 comments

Scala is a big experiment in functional/OOP integration and the jury's still out. If you don't need objects and the JVM, use Haskell instead: you'll learn a lot more.

Clojure has taken the lisp baton from CLisp and Scheme, if you want macros. But even without them, the underlying semantics for concurrency look promising.

If you need to run websites on the JVM, use JRuby on Rails.

imo it depends largely on your co-workers / environment. For instance, where I work (bigco) there is no way a large number of OO-java programmers are going to switch to a functional language like clojure. However, there is a chance that OO-java programmers will switch to scala because the mental models can be similar enough when you're first getting started. That is, you technically can program java-like scala because you have objects, strong-types, assignable variables, etc. So while scala has powerful language features available, the barrier-to-entry is lower (for a "regular" OO-java guy).

With clojure, on the other hand, if you haven't done "functional" programming at a large scale you literally have to relearn "how" to program. You don't have state, you can't assign variables, you only sort-of have objects, and there are all these funny parenthesis all over the place.

So first ask yourself the question "who are you going to be programming with" and "what do you want to learn".

I've written and deployed non-trivial production systems in both and I'm fond of saying that scala drove me to clojure. I'm not trying to start a flame-war or anything [1], so let's start with the good stuff:

* you get functional constructs & concise iterators

* ruby-like mixin functionality is awesome (implicits) - this allows you to architect using composition over inheritance which is a huge win over java imo.

But...

* the syntax of scala can get quite perlish at times (my favorite being the "crying-kissy-face-operator" :_* [2]).

* the strong typing can be maddening. For instance, if you're trying to use two different JSON libraries (as in early days of Lift) you have to do all sorts of ugly type conversions. This leads to type boxing and...

* For "nothingness" tests you have: Null, null, Nil, Nothing, None, and Unit. Fun. [3]

* inline-xml (who asked for this?)

It was when slogging through a Lift-based recommendation system that I discovered clojure and I have to say, I love clojure. You can program in a lisp but still use the gobs of java libraries available. The syntax is straightforward, the performance is good/acceptable, and because it's on the jvm you can use it in Hadoop etc.

So while it does take longer for an OOP-minded person to think in more functional terms, I think you'll find that learning a lisp will make you a better OO programmer.

* [1] I have tons of smart friends who love scala. I like scala better than java, but if I had my pick, I'd pick clojure over scala. YMMV

* [2] http://www.mail-archive.com/liftweb@googlegroups.com/msg0822...

* [3] http://blog.sanaulla.info/2009/07/12/nothingness/

I've learnt and used both. Even after programming in Clojure for a year, I'm more productive in Scala because of its familiarity and because there is less of an "impedance mismatch" between Scala and available Java libraries.

However, I would recommend Clojure as the language to learn. The community is very beginner friendly, the language takes me to interesting places and some of the libraries are so elegant they are an absolute pleasure to use.

I believe learning Clojure is a good investment - as it matures more parts of the Java ecosystem will be covered by Clojure libraries, its a good practical way to learn a Lisp (which is worthwhile in itself) and its a good practical way to appreciate Emacs (which is worthwhile too).

My experience with Clojure is that it forces me to think differently and I like it. I come from java /c background and Clojure drags me kicking and screaming out of my comfort zone. The purity is what I appreciate about Clojure. I am nowhere close to being productive in Clojure ( my start-up codebase is Java and javascript+node ) but one day I will get there.
If you're coming from Java and using a Java IDE you'll probably feel most natural moving to Scala. I personally came to exploring Scala and Clojure with limited Java experience (and a preference for Vim and the command line) so getting started with Clojure via Leiningen was more natural for me. SBT never clicked for me.