Book review: Programming Clojure

Z Jacek Laskowski - Wiki Projektanta Java EE

Grafika:programmingclojure_cover.jpg Programming Clojure by Stuart Halloway (The Pragmatic Programmers, May 2009)

It wasn't an easy task to grasp all the functional programming concepts outlined in the book Programming Clojure, but I'm pretty certain that without Stuart Halloway's writing style and thorough knowledge of the subject it would have been tougher.

"We're drowning in complexity. Much of it is incidental - arising from the way we are solving problems, instead of the problems themselves."

This was the first sentence in the book's "Foreword" by Rich Hickey (the creator of Clojure) that begun my endeavor into functional programming with Clojure at hand. After the many years of object-oriented (Java) and imperative (Java, C, C++) programming of mine I found some spare cycles to give Clojure a try. I can't recall why I decided to read the book at all, but if I had to dig in my head to find the answer it would probably be the recent interest in functional languages in the Java community (the past Groovy/Grails books influenced the decision to some extent too). I was curious what there is in the functional world and I simply couldn't resist having a look at one of them. The only requirement was that it has to run on JVM. Clojure seemed as a good fit. The reason was simple. I remember I couldn't manage to write a application in Haskell not to mention Lisp which I barely knew from playing a little bit with Emacs, but Clojure turned out to be different. This book showed me that it's the functional language I could easily comprehend and play with on the JVM. And since I'm on JVM I can enhance my Java skills with Clojure's functional techniques. It's been said that learning new languages allows you to expand your programming skills. It happened to me after having met Groovy and so did it after having met Clojure.

There're 9 chapters in the book, but it was just the last 9. "Clojure in the Wild" when I found a partial answer to my question on the role of Clojure in my Java programming toolbox. The more the author delved into the intrinsics of Clojure, the often I asked myself Why do I need yet another programming language which is not object-oriented but functional?. I liked the chapter 3. "Working with Java" where I found that writing Java application could be fancier with Clojure and it's really a matter of your personal taste how to approach a task without the ever-temping thinking of using Java for everything. Now I know that the challenge of writing highly concurrent and scalable Java applications is simpler with Clojure. It's bytecode-compatible with any other Java application so a multithreaded application in Java can lay its foundation upon Clojure's immutability and special language concepts for parallel, high-volume processing. The other chapter 6. "Concurrency" explained them pretty well. I never paid much attention to concurrency considering it as a minefield in Java, so it was refreshing finding out that Clojure could handle it in such an elegant way. The chapters 7. "Macros" and 8. "Multimethods" were the others that brought much enjoyment. I'm glad I added macros and multimethods into my programming arsenal. Stuart presented them very well. I would have never considered Java polymorphism as a type relationship that's merely a part of a more general concept of multimethods in Clojure. Very refreshing.

Throughout the book, Stuart builds the Lancet build tool which is Apache Ant-based tool written in Clojure. There're also some other smaller applications, like the Snake or Apache Commons' StringUtils.isBlank() method simplified in Clojure, that are presented in this book with their source code. What I really appreciated was that the author presented just enough source code to draw interest to important pieces of the language with the remaining parts left out (the source code is available from the book's website). Just enough information about the language in 300 pages, but not much about how to use Clojure in real projects with existing Java build tools and frameworks. Although aiming to present the language in its full glory, it missed its real use in Java projects. It was merely 20 pages about the topic in the chapter 9. "Clojure in the Wild" and I feel I needed more. Although the book style is very entertaining and I'm quite sure noone will look for more about Clojure as a language in other materials I was hoping that there'd be more about its use in real Java projects. There was not much about it.

The author included lots of external references for further Clojure and functional programming's research. Clojure is a great functional language that runs on JVM and the book made me confident I should try it out in a project (with Clojure as a new JVM-based programming language under my belt which I'd be pursuing to use I don't think I'm going to be part of any - it could be way too revolutionary). I'm looking forward to leveraging Clojure's functional strenghts in the Wild.

Osobiste