Experimenting with Clojure

In former days, Visual Basic 6 was the language of my choice. A lot of people tried to convince me that VB is crap and I should learn a “real” language like C++. Nevertheless, I was happy with VB and even built some nice stuff with it.

Later, when I switched from Windows to Linux, I was looking for a new language and found Java. I like Java still very much, and it is great to write and compile code only one time and it runs on all platforms (at least in theory. Bolzplatz 2006 was more complex, but anyway it was a good decision to choose Java). But when you become a more experienced developer, you soon notice that Java has several severe limitations (the project where I encountered these problems in particular was CUP2, a parser generator for Java, which was the topic of my Bachelor’s Thesis. There, I had lots of “fun” with reflection and such things).

Some days ago I read Paul Graham’s article called Beating the Averages, which I really recommend reading. He states, that every programmer is happy with his favourite language and is more or less restricted in his thinking. This prevents him from switching to the really most powerful language (which is, as he thinks, LISP).

For already two years I am trying to learn LISP, so far without success (mostly because lack of time). This week I took the time and started some experiments with Clojure, a modern LISP for the JVM. My goal was to replace the Java-SLE-solver of the slur layout engine by Clojure code.

My experiences so far:

  • Clojure is not very easy to understand for a programmer that only worked with imperative languages before
  • Anyway it is possible to learn the basics quite fast, that means, using the features without exactly knowing why or how it works
  • Clojure opens up a new dimension of programming. LISP as a “programmable programming language” allows you to do things that you will never be able to do in Java (for example, please don’t wait for Sun until they finally add closures to Java. They won’t do it ever, I guess).

Actually, I could finish my Gauß-solver, and I like the code. However, since I am a newbie in functional programming, I guess there are lots of things I could optimize. My Java solution needed 300 ms for solving 1.000.000 3×3 SLEs, but my Clojure version needs 33 seconds (ouch!). Here is the code – if you have any suggestions, please tell me 😉

This experiment has encouraged me to gain more experience in LISP now, perhaps we can use some Clojure code in Zong! in the future (it integrates nearly seamlessly into Java!). If not, LISP will at least make me a better programmer.

One thought on “Experimenting with Clojure

  1. Pingback: 1229 errors left to solve for iteration 50 « The Zong! Blog

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.