Erlang Programming by Francesco Cesarini and Simon Thompson
For the past two years in the Erlang community, when someone says I used The Book to learn Erlang, it was an unequivocal reference to Joe Armstrong's book by The Pragmatic Programmers. It has been the guide to learning Erlang, responsible for inducting a whole new generation of developers to the language. Yet, now that Erlang Programming -- by Francesco Cesarini and Simon Thompson, published by O'Reilly -- is out, the use of the phrase The Book will be followed by the question "Which one?"
Erlang Programming is a worthy contender for the best Erlang book, and evidence of the growth and maturity of the community. I received a pre-release copy of the book, which is scheduled to be published in a few weeks, and I spent the weekend exploring it.
First, the inevitable comparison between the two books. Joe Armstrong is probably best described as a prophet of the Erlang world. His book is a polemic for parallel programming in general and Erlang specifically. Why shared nothing is everything, why message passing and the actor model are important, and why 5 nines doesn't make Erlang break a sweat. Joe set out to tell the world why any system sufficiently advanced is an attempt at rebuilding Erlang. Joe succeeded wildly – he produced a book that gently preaches and occasionally dazzles us with one line IP protocol parsing. Speaking for myself, it was the major influence that drew me into the Erlang world.
Francesco and Simon's work is altogether different. It's still for the beginner, but it has the luxury of living in a world where many readers already know why they want to learn Erlang. In fact, it's partially due to the success of Joe's book that this one can be so good. So they don't have to proselytize. They can teach and tell stories. We’re ready to listen and we know why we’re here.
They produced a great book. They could have titled it Practical Erlang Programming, even; it's the best way to describe the book. In just a few days of reading I've learned practical tips on the best way to structure processes and pass requests through the system, to the reason why defensive programming designed to handle every possible input without failing can make your programs much more difficult to debug.
The book starts with a great summary of the happenings in the Erlang world in the past few years, which could be useful to show to your boss if he's still not sure the language has legs. Next, they dive into a summary of basic Erlang, a great primer on data types, atoms, guards, lists, comparing lists and tuples, and the shell. It's the best introduction to Erlang syntax I've read yet.
It moves on into a description of sequential programming, how to use case statements, guards, the “BIFs” (built-in functions), and much more. It even tells us things they’ve left out because they promote bad programming practices, such as the process dictionary, which is an easy way to subvert “shared nothing”.
They provide a good intro to the Erlang debugger, and then dive into concurrent programming. The overview of message passing assumes you know why you would want to pass messages, and spends more time talking about the best way to architect a multi-process system than the specifics of low-level message passing.
A section on Design Patterns gives a great overview of the patterns used in Erlang development, including client/server, finite state machine, and event handler patterns. In general, you can tell that these guys have built a lot of real-time systems with Erlang. Tips for patterns to avoid and real-world reasons pepper the work with the kind of depth that only comes from experience, like why using a particular pattern is wise or foolish.
Error Handling, dynamic functions, and OTP are all given detailed treatment in their own chapters.
Unit testing and Test-Driven development are covered in a separate chapter, with specifics on EUnit. The culture of TDD, which recently has become so popular in the Rails community, is clearly not as prevalent in the Erlang world, so it’s important that this is included.
How to interact with Ruby, Java, and C via Erlang ports is taught, along with a brief mention of how to accomplish interactions between Perl, Python, Haskell and PHP.
ETS and Dets tables are covered as well as Mnesia. The reasons to use and not to use Mnesia are explained thoroughly, with discussions on gotchas in bringing up Mnesia nodes with extremely large tables. Unfortunately CouchDB and MySQL are mentioned but using them is not discussed. This is a real world need – perhaps a whole book on data access with Erlang is in order?
The book concludes in Chapter 20 with a discussion of coding style, best practices, and optimizing programs. I can say that my Erlang code will improve just from reading this section and this chapter alone is worth the price of the book.
What did they leave out? For the beginner, one more chapter on web programming and relational database access would have been a bonus, but the book is thorough enough without it.
So which book would I recommend? If you can afford both, they complement each other well. But, if you had to buy one, I'd recommend this one, mostly because of the practicality and depth. It builds from a great introduction to the Erlang language to in-depth discussions of the most powerful parts of the platform, with a solid focus on best practices throughout. Joe's book has made the converts, now Francesco and Simon's equips the Erlang Faithful with the tools to conquer the world…
The Safari version of the O'Reilly work will be available around June 15th, and the print version should be available the week of June 22nd.