Hacker News new | past | comments | ask | show | jobs | submit login
The Case for Clojure (codetojoy.blogspot.com)
15 points by coglethorpe on May 14, 2009 | hide | past | favorite | 2 comments



'At NFJS shows, a common question is "I only have time to learn one new language on the JVM: which should I pick?".

The easy answer is true: it doesn't matter. Just pick one already!'

So what is the 75% answer to "which other JVM language should I learn?"

I figure it's either Clojure or Scala, but not sure which one. I prefer Clojure and it seems to get a lot of buzz on HN and proggit, but Scala might be a more straightforward "upgrade" path from Java, and might have more users.


I'd say Clojure. Clojure is very small (Scala seems quite complex).

The concurrency support is fantastic. I've never really had the patience to understand programming for multiple processors in other languages because of the complexity of locks. Clojure has lockless concurrency (via STM)- writing applications which take advantage of multiple processors is trivial!

The following shows easy it is to split work between two cores (if you have them). This code counts to 250,000,000 but does so on two separate threads. It takes half the time of performing the operation on a single core.

(def agentA (agent 0)) (def agentB (agent 0))

(defn my-inc2 [v] (loop [x 0 result v] (if (= x 125000000) result (recur (inc x) (inc result)))))

(defn split-my-inc2 [] (send agentA my-inc2) (send agentB my-inc2) (await agentA agentB) (+ @agentA @agentB))




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: