18 Jan 2014

What a great title, eh? Clojure’s a fantastic language for writing DSLs, and yet it’s a hard topic get into. A good book on the subject is just what the Clojure ecosystem needs.

Sadly, this isn’t that book.

The biggest problem is that there’s hardly any content about writing DSLs. This is a ~240 page book, and about 200 of that is just “Intro to Clojure” stuff. That would be fine, but there are much better introductory books out there.

Filler aside, that leaves maybe 40 pages that are actually about writing DSLs. Sadly it’s the weakest stuff in the book. It consists of two examples of using Clojure to wrap existing Java libraries. One’s a Twitter client, the other’s a wrapper around Java’s Date & Calendar classes. And there’s no way around saying this - both are badly written.

It would be a terrible shame if any beginner in Clojure read this stuff and thought it was a good way to proceed. What should be a simple function to read a config file into a map is presented in an overwrought & brittle fashion. Macros are used frequently but never appropriately. Clojure code drops down into Java interop for no good reason at all. And the author seems to have an obsession with dynamically-binding variables, regardless of whether it’s appropriate. I strongly suspect this betrays a lack of understanding about what they’re for. Either way, the Twitter DSL is going to break as soon as you do anything interesting with it, like delay the results. (Stuart Sierra has a great post about it.)

So is there anything here to like? Yes, the author is quite lucid. His technical writing reads easily. I hope he writes a book on another topic one day - but he’ll need to be far better versed in the material.

In the meantime, if you want an intro to Clojure book, check out the superb Joy of Clojure. And if you’re a seasoned Clojure programmer looking for a good book on DSL writing…well…so am I. In the meantime, here’s a good article on one application of the technique…

comments powered by Disqus