Pretty image
Rich Hickey created Clojure, a modern dialect of Lisp that targets the JVM. In this Pragmatic Programmers interview, Rich explains what that means to you.

Have you taken a look at Clojure yet?

Clojure is one of the most interesting new languages to arrive on the recent scene: an elegant, clean, modern version of Lisp created for functional programming, designed for concurrency, and compiling into JVM bytecode.

Clojure addresses the issues that have held Lisp back (libraries, readability, performance) while preserving its virtues. But what’s stirring all the interest in Clojure is its potential for functional programming. As Stuart Holloway points out in Programming Clojure, “Massively multi-core hardware is right around the corner, and functional languages provide a clear approach for taking advantage of it.” This is the application for which Clojure was created, so we knew we had to talk with its creator, Rich Hickey.

ms: I really appreciate your giving this time, Rich. I want to focus on basically one question: Why Clojure? For programmers in various situations, I want to ask: What’s in it for me? Why should I want to read about Clojure? Why should I invest the time to learn it? How would it benefit me to program in Clojure?

rh: Sure thing.

ms: Cool. So say I’m an independent software developer and while maybe I’m not personally feeling the pain of the economic crunch, I do see signs that the nature of my client list may be changing. I want to be constantly learning new languages and technologies that broaden my options. Why should Clojure by on my short list of career-enhancing technologies?

rh: If you have not yet experienced functional programming, Clojure may offer the most approachable way to do so. Some have called it “the Python of functional programming”, and I’ll accept anything good that implies. Its seamless access to the Java ecosystem means you’ll never be at a loss for libraries, and your applications can be delivered in an accepted environment. Clojure is new, but not disconnected. The infrastructure underlying it, the JVM, is quite excellent technology.

ms: The argument for functional languages these days is all about multicore processors and concurrent programming. Let’s say I know something about functional programming and in fact have some very specific need for a functional language for concurrent programming. Why is Clojure that language?

rh: Clojure is designed for concurrent programming, and specifically advocates that a functional style and pervasive immutability are prerequisites for concurrency. The data structures are immutable, and the locals are not “variable.” However, Clojure also recognizes the need for state in real applications, and provides language-supported mechanisms for managing state that avoid the locks-and-deadlocks headaches commonly found in other languages. Among functional languages (Haskell, ML, etc.) Clojure is relatively unusual in being dynamically typed, and in being connected to a mainstream infrastructure.

ms: Let’s talk about that infrastructure. Say I’m a Java developer. I’m not afraid to learn a new language, but I’m not about to abandon the whole Java ecosystem. What does Clojure offer me?

rh: Clojure lets you do just that—learn something new and not give up your investment and knowledge. That’s true of all of the JVM languages, though—Groovy, JRuby etc. Clojure is unique there in giving you the performance of a compiled language and the flexibility of a dynamic language. Performance is closer to Java than to Python. Access to Java from Clojure, and Clojure from Java, is easy, wrapper-free, and fast.

ms: Clojure’s performance may be close to raw Java, but the experience of programming in Clojure is very un-Javalike.

rh: Clojure may be the most different from Java of the popular JVM languages, and it is so for a reason—we are going to have to do things differently if we are going to leverage multicore, and our large OO programs have become spaghetti. If you really want to learn something new, rather than just do what you are currently doing slightly differently, Clojure is a good choice.

ms: OK, imagine you’re talking to an old Lisp hacker from way back, which in fact you are. And let’s say that I’ve moved on. Performance, libraries, fitting in with the crowd, for some reason I left Lisp. Why is Clojure the reason for me to get back into it?

rh: As a Lisp dialect, Clojure offers everything you love about Lisp—interactive development, elegance, succinctness, extensibility, expressiveness. It is aimed squarely at those areas that had caused people to leave, or not be able to use, Lisp in the past, in particular the library and poor citizenship issues. It is poised to leverage the huge amount of work done in Java, and in turn be leveraged by Java programs. In addition, Clojure moves Lisp forward in incorporating some of the best ideas developed over the years—building the core library on interface-based abstractions, lazy sequences, first-class associative data structures, etc. Lisps have been called functional programming languages, Clojure embraces that more deeply than do Common Lisp or Scheme.

ms: Clojure is now at version 1.0. That can mean different things. Beyond being good for exploring functional programming, is Clojure ready for prime time? Say I want to use is right now for production work. How solid is Clojure?

rh: Clojure is quite solid. It has a very small core that rarely changes, and thousands of users pounding on it. It integrates with the Java tool ecosystem, so JVM debuggers, profilers etc work right out of the box. And IDE integration efforts are well underway, with good plugins for NetBeans and IntelliJ.

ms: Let’s try some direct comparisons. Say I’ve devoted some time to learning Erlang. Why should I choose Clojure over Erlang?

rh: I’m loathe to engage in us vs. them, especially with Erlang, which I quite admire. If you truly have an application for which Erlang is best suited, e.g. a low-level distributed communications app with high uptime requirements, it’s hard to beat it. Clojure is more of a general-purpose language, has better compute performance, better in-process SMP concurrency support, and a much better library and interoperability story. For distribution, you can chose from many techniques and tools, including message queues, some of which are written in ... Erlang.

ms: All right, the same question for the new Scala developer. Why should I choose Clojure over Scala?

rh: Clojure is simpler. It is dynamic. Having fewer paradigms to support, it is more focused on being functional. Being a Lisp, it has a regular syntax, and syntactic extensions are very consistent. Not being object-oriented, Clojure libraries have a different structure, encouraging a greater use of generic data structures, yielding higher interoperability. Clojure is based on the idea that immutability and functional programming are more important contributors to program robustness than is static typing. If these values resonate with you, you will likely prefer Clojure, but I certainly expect Clojure and Scala to peacefully coexist.

ms: Well, you’ve convinced me that Clojure is worth a look. Thank you for taking the time to chat with us.

rh: Sure. This was a good exercise. Thanks for suggesting it.

Rich Hickey has over twenty years of experience in software development in a wide variety of projects from broadcast automation to database design.