Why I Love Clojure...
I have been a software engineer, professionally, for about fifteen years. Like a lot of people who write code as a part or pretty much all of their job I did not come to Software from a predictable angle; my degree is a BA in English and American Literature, but in the time that coding has been my bread and butter I have made it my business to learn on a continuous basis.
I started out with HTML and CSS and then quickly added JavaScript into the mix. For a while, before I was actually making money that was all I did, but even back then I tried to learn as much as I could about best practice, to understand the real ins and outs of what I was doing and to produce the best code that I could. This was not mania, or an expression of ego, but simply an extension of the values that I had learned from my parents, my grandparents and my education. From all of those sources I had gleaned a common theme — understanding is the key to doing something well.
When I decided to make the transition to programming as a job, I took some time out from my first career (media sales), and invested in some commercial training in “web development” that led me down a predictable path to Open Source technologies and got me going on the road to software engineering proper by introducing me to PHP.
PHP is a much maligned language and platform, in many cases with good reason, but as a technology it has played a part in putting food on my table for fifteen years now, and it is hard to deny that it has been instrumental in at least the inception of some pretty major forces on the internet, such as Facebook and Flickr. None of that can change the very real fact that it has some pretty major flaws as a language and as a platform. This is a well-trod road, and other writers have covered the ground more than adequately. On that basis I will simply point you at their work and allow you to decide whether or not you want to go off on that tangent. I would recommend that you consider the arguments in this article, and this one as well. Clearly PHP has gone through various improvements since both of these articles, and the appearance of HHVM and Hack-Lang have moved the debate slightly, but for the purposes of this essay I am going to stick with the idea that back in 2007 when I started to realise that there were some serious deficiencies with my language of choice, that all of the arguments laid out in those articles were entirely valid.
So there I was, in 2007, thinking what should I learn and use next? In the first instance I turned to Python, which I had dabbled with a little a few years previously. Python is a great tool, an excellent programming language whose star is on the rise, but I am not here to talk about Python. As I was learning some of Python’s brilliance I had a very important conversation with a colleague of mine called Nigel.
Nigel was, and I imagine still is, a bit of a genius. He was working at SpinVox at the same time as me, initially coming into the business to help us with a nasty mess of legacy Perl code that was essentially a prototype that became production code (this happens in all start-ups, the ones that claim it did not are almost certainly lying). Nigel was not very complimentary about PHP, and even then I was starting to think in a reasonably negative way about it myself, but a lot of the things that he said made sense. Anyway, we were talking one day and he said to me something to the effect of:
“If you really want to understand programming, what you really need to do is learn Lisp.”
After this pronouncement he essentially performed an insinuated ‘drop the mic’ and headed for the kitchen, presumably in search of a beverage. Later that day he sent me a link to this web-comic from the amazingly awesome xkcd.
Clearly he was making a joke about the fact that his workload was all in Perl…
Nevertheless, his words stuck with me, and in my own time over the next couple of weeks I investigated Lisp as best I could as an English Graduate with a reasonable grounding in and understanding of PHP and Python. I came to a disappointing conclusion — Lisp might be fascinating, but coding in it and even more importantly using it in any meaningful way was going to be next to impossible. Sure there were a number of implementations of Lisp that were accessible to me as a Linux and Mac user at that time, but frankly they were not very friendly, not very well supported and lacking in tools and libraries in a way that made them interesting in an intellectual sense, but not much use unless one was already working in an academic or research heavy area of Software Engineering.
I was downcast, but soldiered on with Python and in the following years gained a level of proficiency and love with and for Ruby (though not Rails) as well.
Fast forward to 2009… I was working for another startup, Rivermuse. We were trying to disrupt the Network Monitoring market and the engineering group had a wide variety of skills between us, in C, C++, Python, PHP, Ruby, C# and Java to name but a few. During one of our many conversations about new and upcoming tech, someone mentioned Clojure, as I recall they found it laughable that anyone would implement Lisp on the JVM. I did not find it laughable, in fact something clicked in my head and I realised that if it had been done right, then a lot of the ‘problems’ I had detected about Lisp two years before were likely to be washed away by the fact of the ubiquity of the JVM. I remember looking at the website and getting excited, but then failing to follow through on really delving into this new language.
It was not until December 2011 that I really, properly discovered Clojure. I was on a long vacation in South Africa and though I did not have a lot of time to myself, as we were there with our new seven month old daughter, and we were attempting to spend time with my wife’s family, I did manage to read Stuart Halloway’s excellent Programming Clojure and start to futz about with the language, mostly in the REPL.
When I got back to London, I started attending the London Clojure Dojo (there was only one a month back then), run by the London Clojurians. They are now running two Dojos a month, plus other events on a regular basis, and I commend them to you if you can get to them. They are free. If you fancy running your own Code Dojo, then their advice and guidelines on running one is a great resource.
Here is where I reveal one of the reasons why I love Clojure; The Community. The people that I met at those Clojure Dojos were open, friendly and incredibly generous with their time. I learned so much from the people that I met and worked with at those events, and even as I became more confident they were happy to talk to me about the harder questions.
With the help of the London community, in person, and the wider community on the Internet I got to be reasonably proficient with the language, and did some small projects with Clojure. Here is the second thing that I love about the language; the Utility.
I have looked at Clojure to solve a bunch of different problems, and every time I have found its Utility in three areas:
- The way in which I can use Emacs and the REPL side by side to check my ideas and see whether or not I am going in the right direction has led to me being able to solve problems much more quickly.
- The finished implementation has always been far less code than any of the other languages that I am familiar with, and when I leave it for a few weeks and come back I tend to find that I understand it right away.
- The combination of #1 and #2 above means that I have fun with the process in a way that I had started to find lacking, even in Ruby.
Being a Functional language, Clojure has forced me to re-examine a lot of the ideas and standard approaches I had previously with regard to software design. This is the third thing that I love about Clojure: the Functional Paradigm.
Now, it is true that there are a lot of great, stable languages out there which offer very similarly Functional Paradigms, such as Scala, Haskell, OCaml and Elixir (to name but a few, and one acquaintance would probably want me to take this opportunity to mention Idris as well, so there you go Bodil), but I love Clojure because it allows me to use the Functional Paradigm on the JVM. “Scala does that!”, I hear you cry. Well it does, but Scala also allows developers to avoid Functional if they want to, and I like a tool that has no ambiguities.
By being ONLY a Functional Language, Clojure has a purity that Scala does not (though I am sure there will be those reading this that wonder why I am not a Haskell fan if I yearn for purity in this regard), and there are benefits to this. Functions are first-class citizens in Clojure and always have been, because it is a Lisp. Sure, there are Lambdas in Java now, but you don’t have to use them… Clojure offers the idea of Immutable State as well, and when these two ideas are combined, one finds a place where code is genuinely reliable in a way that Object Orientated approaches simply cannot come close to.
So why is the JVM such a big win? Well, for one thing Java is established, ubiquitous and for all its own ills a powerful tool in its own right. Enterprises large and small the World over have Java on the stack, so using Clojure is only a learning experience away for a large number of software engineers, and if it offers something that those engineers want or need there is no real infrastructure issue with running it alongside existing Java, Scala, Groovy, Jython or JRuby, meaning that the idea of Polyglot Development is now a worthwhile reality for a lot of organisations. At last engineers have a wide range of language tools before them from which they can pick and choose the best one for any given problem or domain, and all being on the same runtime means that there is homogeneity on the stack, even if the syntax shows great diversity.
When taking that Polyglot ideal into account, here is the penultimate reason why I love Clojure, but it is directly a result of the first three, and that is; the Ecosystem.
By dint of being on the JVM and having a wealth of great Java to draw upon, either to wrap existing, powerful Java libraries like Jackson and JodaTime, or to take courage from the backing of a stable established stack and simply commit to creating great libraries, like Ring, Liberator, Bidi, Modular, Core.Async, Core.Logic, HTTP-Kit, and many, many others, the Community has created a powerful and efficient Ecosystem around this amazing emerging language.
So, with all of this goodness, what is the final reason for why I love Clojure?
Clojure reminded me how much excitement and joy there was to be found in learning something completely new.
When I learned Python and Ruby I realised that I was learning better implementations of the same paradigm as PHP. Learning Clojure showed me, anew, the joy of wrapping my head around something different and exciting and powerful (as it turned out). Since I got this wonderful reminder from Clojure I am trying to cling to it, to continue to learn new things, different things, and do you know what? It feels great!
I am learning / teaching myself ClojureScript at the moment; I can already tell that I will have something new to love about Clojure, very very soon…
(om/root (fn [data owner] (reify om/IRender (render [_] (dom/h1 nil (:text data))))) app-state {:target (. js/document (getElementById “app0”))})