Better late than never, here is a quick check of some of my technical readings from last Summer. Let’s start with Functional Programming: A PragPub Anthology, by Michael Swaine and the PragPub writers.
I did not read the full book, but only the chapters I was interested in. Among the 5 different functional PLs discussed in the book–Scala, Haskell, Clojure, Elixir, and Swift (pending a single chapter on Lua)–I mostly focused on Clojure, Elixir, and Swift, knowing that I would probably never have any use of Elixir. I only went through the chapters about Scala. I like the way the authors lay the subject basis for the functional approach to programming when they say that it is all about functions, immutability, and above all “it’s a way of thinking.”
The choice of syntax isn’t arbitrary. It enables the most powerful metaprogramming system yet created. It’s powerful enough that the majority of the language is implemented using it. Looking at it another way, a Clojure developer has the power of a compiler writer at their fingertips.
Regarding Clojure, there is a short interview with Rich Hickey. Clojure is a LISP, so the code is data, and there is a powerful macro system under the hood. The language also features an unique approach to the concepts of identity (an entity associated with a series of values over time), value (an immutable piece of data), and state (the value of an identity at point in time), as discussed in Chapter 8. See also this presentation on identity, state and value (PDF). Persistent data structures (maps, vectors and sets) are very specific to Clojure and its way of managing concurrency1 since these entities are able to preserve their previous version where they are modified, thanks to structural sharing (provided, e.g., vectors are large enough) and “managed reference types”, which ensures that all of the references (atoms, agents, or refs) being managed point at the latest value for a given identity. For instance, when you de-reference some data from an atom, it won’t change without you knowing it or being able to return to the previous state. Chapter 9 adds further refinements to the use of agents and refs in the context of concurrent programming, considering an example of a system that keeps track of television series and episodes. While many people seem to complain about Clojure error messages and stack trace (see, e.g., Reddit, SO, or the internet to name a few threads), it has quite improved over the years, and if you are using Cider you are in good hands for a long time. In any case, Stuart Halloway describes the condition system
error-type that was part of clojure-contrib and that happens to provide an way elegant logging solution.
I will probably have more to say on Clojure once I finish writing my review of Getting Clojure, by Russ Olsen.
Programming is not about data. It’s about transforming data.
I don’t know anything about Elixir, except what I read here and there, especially on Evan Miller’s website. However, I learned a few things, especially about pattern matching, which in Elixir is the only way to bind a value to a variable or parameter. Moreover, pattern matching can be applied to anonymous or named functions. There is a nice illustration based on the Luhn algorithm in Chapter 11. And also that “dependently typed languages are an elegant combination of computation and reasoning.” (That one was quite easy since it is part of the TL;DR)
That’s the driving force behind the new hybrid languages: we want to be able to minimize mutability, but it’s a mutable world.
The chapters on Swift were interesting, especially the one on functions2 and methods (Chapter 25), but I think I learned more from other books, probably because they were more focused on problems I tackle at work (e.g., Classic Computer Science Problems in Swift; see also, High Performance Numeric Programming with Swift: Explorations and Reflections). Anyway, I believe Swift is a nice language and I’d like to have time to invest some time digging into it a bit more. Again, Evan Miller has an interesting review on the language (see also the update here). And of course, there’s all the nice stuff put by Chris Eidhof and Ole Begemann.