Over the past few days I have been teaching myself the very basics of Clojure (with a bit of difficulty), and I have been questioning whether or not Clojure is worth the trouble of learning about immutability, concurrency, and functional programming. After all, Clojure is one of the youngest and least cared about programming languages around, so why should the trouble be worth the time?
In this blog post I discuss whether or not Clojure is worth learning in my first installation on a line of blog posts concerning Clojure and functional programming.
Clojure is hard
The title says it all. As a programmer that has mostly worked in languages within the Algol branch (C++, Java, etc) the functional paradigm seems like a scary thing. Not being able to change the state of a vector or a map is equally as frightening at first, and having threads be such an integral part of the language does not soften the situation. Learning Clojure, especially since it is such a young language, is no easy task. Having a background in Python (or Lisp) and Java is almost an absolute must before you can even consider Clojure.
As you will read this hard work pays off.
Why Clojure is a good idea
A while ago I had a foray into Lisp and really left Lisp half-learned before I got antsy. The most recent documentation regarding Lisp was from around 2002, it had no unified (or good, for that matter) graphical toolkit, and it had major gaps in its usability in terms of strange forms (loop) and stack overhead when you don't want to use them. Although Lisp has its flaws, it is a wonderful language that allows the programmer to be concise with their code through something called Higher Order Functions. A single function can serve multiple purposes, a trait that I call programmatic nonlocality. In fact, I was able to rewrite an old text library from Java (originally 320-some lines) in less than 100 using Lisp.
However, Lisp has the shortcomings and the dead community that I described above. Meanwhile, the C*, Vala, Python, and especially Java communities (since the dawn of Android) have been experiencing a golden age of popularity. Not a single student in my High School Java class had written in Lisp; only one had so much as heard of its existence. Clojure is Lisp that compiles to the Java Virtual Machine, as you probably know if you are reading this article. That gives it the power to be compatible backwards and forwards with Java. This is called interoperability. Now you can have the elegance of Lisp without the guilt of using a nonpractical language. All of the Java libraries become available to you, and any Clojure libraries become available in Java. This comes into great use when dealing with functions conditionally has caused a massive decision tree, or when working with data trees requires good recursive capabilities. The "Hard Part" can be written in Clojure, and then you leave the sloppy imperative stuff up to Java.
The ability to enhance your Java programs with this "secret sauce" of computing is a trait that you should definitely look for as a programmer that is always looking to improve themselves. I have also found that the principles of Clojure are transferable to other programming languages. A programmer will think of how to solve a problem in Clojure and then implement it in whatever language they choose.
Most of the issues with Clojure will probably be short lived. In the world of programming Clojure is one of the youngest languages out there. (Right up there with Vala and LOLcode). The documentation is outdated, and bugs still exist within the language. Also, Clojure is not used on many projects yet because of its immaturity. This means that you may be the only person on your team that knows Clojure. Of course, that also implies that when you need help there will be a very limited community to lend you a hand.
In general, most of the problems that Clojure faces comes from a small community of developers lucky enough to hear about Clojure before it gets big. I am convinced that Clojure will become more-and-more relevant in the coming years. Clojure is a language designed specifically to solve the problems introduced by other languages, and to create a modern toolkit for modern applications such as parallelism.
Clojure can be used wherever the 9 billion devices that use Java are used, even for Android applications. It compiles to a .class file that can interop with Java seamlessly.
Clojure is a strange language born out of a strange paradigm and the striving for perfection; the repair of the shortcomings of the languages before it. Learning Clojure will increase your ability as a programmer in general and how you use Java specifically to create efficient applications. Clojure is definitely worth learning, despite how hard it is for beginners and intermediate programmers alike.