I’ve just finished working through “Web Development with Clojure” by Dmitry Sotnikov (Note: I read the beta version (b5, b6) but I believe it’s pretty close to the final version apart from formatting and corrections).
The author is one of the creators of the luminus framework and it shows in this book. The style of code and how he organizes his code is more or less identical to that espoused by luminus.
When I initially perused the table-of-contents for this book online, I wasn’t impressed. It seemed like a short tutorial on building a basic picture gallery. Several of the libraries that I like to use for clojure web development were almost entirely absent. But after reading it I realize that it provides a good base for building clojure web-apps - and while it focuses on different libraries that those I’ve used up to now, and it organizes code differently to how I have been organizing mine - it does a good job of showing you how to drop in libraries for particular parts of your app.
And that’s the thing with web development in clojure. There are lots of libraries and very few frameworks. This can be offputting for someone who has spent the last few years working in a monolithic framework such as rails or django. In contrast, clojure espouses the use of small reusable libraries. “Libraries, not frameworks” is the mantra.
One of the most common questions I hear from rails devs who are interested in clojure is “Which web framework should I use? What’s the rails equivalent in clojure-land?” Once you’ve gotten comfortable with clojure you’ll realize that the code you write in clojure is usually simpler and more reusable than what you would write in rails. In that context, a monolithic framework such as rails no longer makes as much sense. Why impose the restrictions of a monolithic framework on yourself when you can easily compose a set of libraries to behave exactly how you want. Basically you create your own custom framework that behaves exactly how you want.
If you’re a rails dev, this probably sounds like a lot of work, but by the time you work through this book you’ll easily be able to do that. The luminus framework is at it’s core a set of decisions on which libraries to use and how to organize your code. Once you’ve decided which libraries you want to use and how you want to organize your code, you can create yourself a lein template and you’ve got yourself a framework.
So who is this book for? It’s probably too dense and moves too fast to be suitable for someone who hasn’t build web apps in some other language (I could be wrong). But for someone who is fairly experienced at building web apps in some other language (cough ruby/rails), knows a bit of clojure and is interested in how you do web-development in clojure, I’d say this book is a good primer. It covers the basics, chooses a few libraries and shows you how to use them, outlines some alternative libraries and gives you the tools/knowledge to continue exploring the clojuer web-development universe.
One thing I think would add to this book is an appendix outlining or at least listing all the alternative libraries for various parts of your web-stack. There is one chapter that outlines alternatives for some of the library choices and shows you how to adapt the sample app. This chapter is tremendously useful for showing how you can easily add switch libraries to your web app but I feel an appendix outlining all the options would be useful.
So in summary, this book exceeded my expectations (which were probably influenced by by my biases/preferences for particular libraries). It’s an example of my favourite type of programming book: short, no fluff and provides lots of value.
For the curious, the library stack used in this book is:
- ring, obviously.
- lib-noir for sessions and validation.
- compojure for routing.
- hiccup for templating, later replaced with selmer.
- database access using jdbc, later replaced with korma.