Book Review: Living Clojure

Living Clojure (O'Reilly / Meier)

Living Clojure (O’Reilly / Meier)

Back in the 1990’s I often bought these “Java/C++/DirectX/whatever in 30 hours” books. It always took more than 30 hours to go through them, but after reading them you often had some ground to step on and a basic idea about how to get things working. What’s common practice for mainstream languages happens rather seldom for specialized or niche languages like Clojure: almost all Clojure books I’ve read / browsed so far often start at first gear, but accelerate too fast in their subsequent chapters. They are written by experts for other soon-to-be experts. I have started various books of this provenance and put them back into the shelf for later reading. An experience that can be both annoying (another author who can’t explain things) and depressing (I’m never going to learn this) for the reader.

Carin Meier’s book is different. You should have, however, some experience in programming, because “Living Clojure” is about Clojure and won’t teach you programming skills. It’s split into two parts, the first one is about the language itself, the second one is a seven weeks training program. Let’s have a look at both of them.

Now Is The Time

When I started learning Clojure I was almost overwhelmed by the various sources of information. I was used to Perl and C# programming, and when I dipped my toes into the Lisp pool, I finally started using Emacs. Don’t ask me about my motivation for this. Okay, here it is: “You’re almost 50 and you didn’t even try to learn the most effective tools of your discipline. Now is the time!” And it was hard, because Emacs’ learning curve is steep, steeper, steepest. And Lisp is, well, different. Taking Clojure along added even more complexity, because both languages are well distinguishable, but at least Emacs provided a common platform for both. And what has this to do with Carin Meier’s book? It skips all this stuff until chapter 5 where is briefly presents the recent editors and environments. Meier’s completely right when she states that you shouldn’t learn Emacs and Clojure at the same time. In fact, Meier emphasizes the importance of taking time to grasp Clojure and functional programming: an advice you cannot take seriously enough, especially if you’re coming from a traditional (i.e. imperative) programming language. You shouldn’t expect a thorough introduction to functional programming, either: what you learn is to do a couple of swim strokes without sinking in that aforementioned pool.

A Guided Tour of Clojure

The individual chapters of part 1 are written fluently, they are giving a good start position. Some topics (especially recursion) go a bit short, others (state and concurrency) cannot be really estimated by a reader unexperienced in functional programming. Perhaps in these chapters the basic problem with learning a new programming paradigm (like FP) emerges: the principles are easy; they have consequences you can’t foresee yet; the language itself is easy, too; the plethora of functions (and their application) is just overwhelming. So beginning with chapter 3 you start to feel a bit uneasy. That’s not the fault of the book; it’s for the first time you realize that you definitely have left your comfort zone.

The Java Interop chapter is nice but nothing you would need in the first place (I guess nobody starts learning Clojure because it allows you to call Java methods.) Chapter 5 is a great intro into Leiningen, another essential tool that seemed very enigmatic to me at first, but Meier makes you understand and gain an overview of its options. And since the core language is so easy, you’re already learning asynchronous communication while you barely reached page 100! This is surprising for somebody with a C background, because that’s the stuff you wouldn’t expect in a beginner’s book. And, consequentially, chapter 7 introduces more expert material, and that’s how to set up a website using all traits à jour, JSON, the Cheshire Library, Ring; you’re making ClojureScript run in your browser – it’s a bit tour de force, and not everything might be immediately necessary, but also this chapter gives you a good start should you ever plan to undertake a web project with Clojure. After reading the Macros chapter you’re feeling either enlightened or exhausted. So this is how Clojure feels in just 150 pages.

Living Clojure Training Program

Is it really that simple? Part 2 of “Living Clojure” will tell you, because this is the training program. And this is something I haven’t seen in other Clojure books yet, it’s both more and less than these ‘exercises’ paragraphs in common textbooks. But before the first exercises start causing you headache, you are going to learn how to join the Clojure community. This is really new for somebody who’s used to textbooks that have only a bibliographical reference to offer; presenting a language not just as a technical means but also as a living environment is a refreshing experience. Learning where to find all important sources, forums, wikis, libraries etc. saves you hours and hours of time. Time you will need for studying all these sources. All references given in the book are current, relevant, and working. And now to the training part!

This part is the smallest one in the whole book, but it’s one that will keep you busy for several weeks if you intend to do this training. The book’s name is “Living Clojure”, and the training wants you to keep you busy with Clojure, day by day. This is done by borrowing a large part of the 4Clojure koans, and where it’s appropriate, Meier comments the respective exercise. I think, this approach is legitimate; it’s better than just saying: “look at that website and solve all its puzzles”. Appearing in a book, being part of a time schedule, slightly commented and themed, it certainly makes sense to use 4Clojure’s exercises. However, I got sometimes the impression that time was running out for the author, because 1) not every easy 4Clojure exercise is “easy”, and 2) discussing a solution is as important as solving a problem, in my opinion (and, unfortunately, there’s no discussion in 4Clojure). That’s what I’m missing here, because the first part has taught you a lot of details, but that doesn’t mean that you already grasped the mindset needed for functional programming. Being able to solve the koans will need a lot of energy and readiness to invest time, much more than reading the whole book. The projects as of week 4 are more ambitious and make you write larger code. (I haven’t reached them yet.) Chapter 11 is a foresight on Clojure 1.7 (and its transducers) which was released only a few weeks ago.

Bottom Line

“Living Clojure” is a good primer that lets you meet many important techniques and tricks about Clojure. It’s not an introduction to functional programming, it just presents the basics. The chief work is investing time for all these skills and exercises, enabling you to write Clojure code more and more fluently. And after that, you can get out these still unread expert books: you’re ready for them.

Carin Meyer’s blog is both a source of Clojure projects and a diary: see here.

Living Clojure, Carin Meier, O’Reilly, April 2015 (first ed.), 220 pages

About Manfred Berndtgen

Manfred Berndtgen, maintainer of this site, is a part-time researcher with enough spare time for doing useless things and sharing them with the rest of the world. His main photographic subjects are made of plants or stones, and since he's learning Haskell everything seems functional to him.