Just got my dead tree version of Programming Clojure by Stuart Halloway Friday, which reminded me I need to write a blog post about it.
Clojure is a functional programming language built on top of the Java Virtual Machine. The things that make it interesting:
- It’s a Lisp-style language, but it removes some of the parenthesis
- Has a different concurrency model that support transactions against variables.
The latter point is really interesting to me. I’ve spent a fair amount of my life near processors, because I do a lot of work that’s meant to run either in the kernel (device drivers) or because my work is targeting an embedded environment (either with or without an operating system). So I’m pretty familiar with the nuances and pitfalls of locking and synchronization. Clojure’s model could be a step in the right direction. I think it’s too soon to tell, but it’s pretty compelling.
Back to the book. I originally bought Programming Clojure as a Beta Book. Since then I’ve read the book twice more(!), and I must say, it was just as enjoyable reading it the third time as the first.
First, let me say it one more time for those who don’t know me: I do not have a Computer Science degree. I majored in Electrical Engineering, and my deep passion for computers and solving problems landed me in the computer science realm. That means I don’t have a background in data structures and algorithms, nor did I take a course that surveyed the wide and varying languages that are out there like so many computer scientists have to take as part of their curriculum. So, while I once wrote a bunch of lisp macros for XEmacs, I certainly don’t claim to understand all of it’s nuances and why some decisions were made the way they were.
However, Programming Clojure won’t leave you stranded. In fact, I found it to be quite the opposite. Imperative languages are so popular, that Stuart felt the need to walk through why a functional programming language is useful, how it fits into today’s world, and more importantly he walks you through the concepts step-by-step throughout the entire book. Programming Clojure felt as much like an introduction to functional programming as it did an introduction to Clojure. For some the more advanced folks who are fluent in a functional programming language, you might find this a distraction. However, I suspect more people are in my boat, and will find Stuart’s treatment of great benefit.
The book starts off with a basic introduction to functional programming and Clojure’s functional programming constructs. Since almost anyone who is looking at Clojure is probably looking to make use of the Java ecosystem, Stuart also shows off integration between Java and Clojure really early on. He continues throughout the book to build on key concepts of functional programming and lisp: sequences, lazy evaluation, and macros. He takes a break in between and spends a whole chapter on Clojure’s concurrency model: Software Transactional Memory. Finally, he finishes off the book with how to integrate unit testing (yay!), database access, and web development with Clojure.
The book is loaded with programming examples (that actually work!), so it’s very easy to follow the book and try things as you go. All you need is the Clojure jar, an editor, and you pretty much have everything you need at that point.
If I were more clever, I’d sign off with a Clojure snippet. Unfortunately, I’m not that clever when my son is sitting on my lap insisting on playing with the mouse. :-) I will say that the book is an easy read, and if you have an application that needs to be concurrent, consider reading Programming Clojure. Whether or not you end up using Clojure, I believe functional languages are closer to coming up with a much more usable concurrency paradigm than the current threading/locking scheme we have today. As I said earlier, Programming Clojure is as good an introduction to Clojure as it is functional programming, so why not start off with this book?