Friday, May 13, 2011

Clojure

I've started to write code in Clojure, which is a LISP dialect created for the JVM.

This means that the code has the aesthetics that can only be achieved when doing functional programming, while maintaining the ability to fully interact with existing Java based libraries and code.

More then that, Clojure comes along with a modern (almost futuristic) approach to concurrency, way different then the one Java has.

This is extremely important for a programming language, let me explain why.

A good way to think of concurrency (and especially data concurrency ) in programming  is to think about it as a mine field, where the locations in which the threads are interleaving and handling the same data are mines. Your code is the field.

Java's approach is "I'll give you the ability to place mines and I'll  also give you these small cocktail umbrellas to mark where the mines are". You just have to hope that you placed these little cute umbrellas in the right places and covered with them all the ways to access the mines. This is tough to do right in small scale software (where there are very few developers). Practically impossible to do right in large scale software (where there are too many developers).

Clojure's approach is different. It says "put as many mines as you want, I'll cover it with so much concrete, that it doesn't matter how many users are travelling in the field". The concrete itself is composed of immutable data, actors/agents model and software transaction memory.

(BTW, JavaScript approach can be summed up as "there shell be no mines")

I will not start to explain why concurrency is important, if you don't know, then probably you didn't read all the way up to here...

This is a delightful language to use (higher order function is by far the most beautiful idea in programming). It is powerful, efficient with a "no fluff just stuff" attitude with a potential to take your code to places that OO just can't go.

I guess that this is the reason why one of the first books written about Clojure is called "The Joy of Clojure", not sure that there are such titles about C or Java (a book with a similar title about C++ is probably aimed at the masochist community).

Try it, you will not regret and will not look back.

No comments: