Q&A with author Alex Miller
Q: Why did you get involved with the 3rd edition of Programming Clojure?
A: The first edition of Programming Clojure was important because it was the first Clojure book available. Stuart Halloway worked closely with Rich Hickey, the creator of Clojure, to capture the key ideas behind Clojure and let that philosophy shine through. I first picked up Clojure about the time this book was published and I found it to be a helpful and insightful guide. It has been a great challenge and pleasure to revisit this material that I used to learn Clojure myself from the other side of the page.
Q: What’s changed since the 2nd edition?
A: Aaron Bedra provided an excellent update in the second edition of Programming Clojure for the release of Clojure 1.3, which provided both a lot of new features and an overhaul of certain parts of the language (like numerics). In this third edition, everything has been brought up to date with Clojure 1.9, the latest release. I have included new material on features added since the last edition like transducers and spec. Additionally, many of the longer examples have been updated to take advantage of the latest features and functions of the language.
Q: What kinds of problems are best solved with Clojure?
A: Clojure was always conceived with the intent to be a general purpose language targeted at domains where its hosted languages (Java, C#, JavaScript) were prevalent. Those languages cover a lot of territory, and Clojure has been used in a wide variety of domains as well. However, the majority of Clojure developers are creating multi-tier information systems (server + web UI) where they can share code (in Clojure and ClojureScript) across the tiers. These kinds of systems take full advantage of Clojure’s portability and its focus on the representation and transformation of information. Typical domains that take maximum advantage are financial services, ecommerce, healthcare, energy, legal, entertainment, and more.
Q: How portable is code between the different dialects of Clojure, ClojureScript, and ClojureCLR?
A: At the heart of Clojure is the ability to represent data (using Clojure collections) and transform it using sequences and transducers. In almost all cases, code that creates and manipulates data, controls flow, or creates and invokes functions is exactly the same on all of these platforms. The areas where they start to differ is where the host platforms differ with respect to managing state or concurrency, or working with I/O, date/time, etc – places where Clojure and its dialects rely more heavily on the hosted platform. However, Clojure includes the ability to create conditional code such that minor host differences can be covered in a single cross-platform source file and users of that code don’t have to worry about those differences.
Q: What’s the role of the new Clojure spec library?
A: The spec library is perhaps the most important new feature added to Clojure in years. Clojure does a fantastic job of providing tools for representing any domain in data, and then manipulating that data. However, the combination of dynamic typing and generic data transformation means that while code be very concise and reusable, it’s sometimes hard to see at a glance the shape of the data flowing through your system. Specs provide a language for describing your data and the functions that use it. This language is based on predicate functions (code you already have) and once you write your specs you gain a whole host of tools for using them to validate data according to a spec, parse data into its constituent pieces, explain why an invalid value is invalid, automatically generate example data, detect invalid function calls, and even automatically test functions using generated data. Specs are quickly becoming an essential part of the Clojure toolset for managing data.