prose :: and :: conz


Next stop: Clojure

While I have developed a reputation for loving Scala, I actually looked at Clojure first. I was a bit turned off by all of the parenthesis and prefix notation. Now that I’ve dove head first into functional programming, I now think I’ll *get* it the second time around (yeah Mom, I know… yet another post about code rather than the kids).

But why bother? Well firstly, it’s a dialect of Lisp. It’s the second-oldest high-level programming language, and it has managed to stand the test of time. That alone is reason enough for me to learn it. It’s not just a toy either. There are several folks in the community who I highly regard which are using Clojure. Most notably is the creator Rich Hickey, who I have concluded is a genius after his keynote “Simple Made Easy” and the creation of the Datomic database. I also hear no end of Clojure/Lisp talk from fogus on Twitter and from none other than my huntfunc colleague Bret.

More importantly, there are a few compelling things that are going on in Clojure which is the thrust behind this post. Generally when building web applications, you have to be a polyglot programmer. You have your server-side language (Java, C#, Scala), data query language (SQL), client languages (HTML, JavaScript, CSS), mobile app languages (Java, Objective-C), and all the crap in between (XML, JSP). Clojure has the potential to really collapse this down.

As a JVM-language, it’s a natural candidate for your server-side logic. There are already several web frameworks to choose from (and by using the word “frameworks” rather than “libraries”, I’m already out of line). Then there is ClojureScript which is a Clojure-to-JavaScript compiler. Now I’m not a big fan of compiling to other high-level languages, but I like the idea of having both my client and server coded in the same language. However, this alone is not compelling in my book.

But that’s old news. My interest in Clojure got resparked by this tweet. It is a project called ClojureC which targets C as the backend of Clojure. I almost ignored this tweet. Fortunately, I did open it and found the mobile platform notes where both Android and iOS are mentioned. If these guys are successful, then we’re looking at also having our mobile applications in the same language! Couple this with the fact that Datomic works natively in Clojure, we may now use the term “compelling”.

I certainly don’t mind learning multiple languages. In fact, I embrace it. However, it can be a maintenance problem. Consider a simple registration form. My server-side code verifies that you submitted the same password in both boxes. Soon I plan to whip up some JavaScript to perform the check client-side to improve the user experience. While this may be a trivial validation, the fact that I coded it twice will never sit well with me. I can envision having my validation code written once in Clojure and executed on the server, the web client, and now the mobile devices.

assert(interest.piqued)


Olde Comments
  1. Yes, but two days ago you were singing the praises of static type checking – which ain’t Clojure (I know – consistency being the hobgoblin of little minds etc). One day the world will (re)discover Dylan (but I’m not holding my breath :).

    • barnesjd says:

      Ah yes, I know. I now regret that I omitted my lament that it wasn’t statically typed. But FWIW, as much as I prefer static typing, I’m not about to say that’s all I’ll ever do. Thanks for reading!

  2. […] of the day, the more compelling half of the day… As I’ve mentioned before on this blog, Clojure was the first functional language on the JVM I looked at. In that post I also expressed a renewed interest in Clojure, and now a little over a year later I […]

Tagged with: functional-programming (31), web-development (19), polyglot (7), clojure (5)