Erlang Inside Rotating Header Image

Sneak Preview of O’Reilly’s new book: 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, and 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” – its 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 diffcult to debug.

The book starts with a great summary of the happenings in the Erlang world in the past few years, 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 for why using a particular pattern is wise or foolish pepper the work with depth that only comes from experience.

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.

5 Comments

  1. Thanks for this post. Amazon.DE says the book will be available on July 15th for 35 EUR…Amazon.co.uk says it will be available on June 26th for 20 GBP (~ 23 eur) :P …hard choice…;).

    Anyways…thanks for this useful post. It helped me to make a choice.

    Cheers,
    Andreas.

  2. This is great news!

    F spook well about his writing when me and my classmates participated in one of his courses at the IT-university in Gothenburg, Sweden. I believe some of the exercises was drawn directly from the book, and I remember the flow of the first chapters to be really helpful to programmers who are new to functional programming, and Erlang.

    Regards,
    Marcus

  3. Praveen says:

    I can’t wait for the book to get released. I’ve holding out buying Joe’s book since this was in progress.
    Like you mentioned, RDBMS connectivity is probably biggest challenge for erlang developers.

  4. Jamaal says:

    Erlang’s just itching for a web book, and I’m sure that once Nitrogen stabilizes a bit, and Webmachine gets deployed on a few more sites (and gets chunked bodies, yay!), and with nice template libs like ErlyDTL around, it’ll be started soon. An RDBMS lib is the major flaw right now (Yariv’s out of active dev lib notwithstanding) for people who need that sort of thing (for example, people who use Crystal Reports for some of their reporting.) ODBC is fine for now – but if there was a good mysql connectivity lib, somebody would start the book tomorrow, rather than next year.

    Everybody should check this out though: http://bitbucket.org/will/epgsql/ (a postgres is fine too!)

  5. What a great book! I have been gobbling up everything that I can related to Erlang in the last several months (forums, books by Joe Armstrong (4 stars), Martin Logan (4 stars) and now, the best of all … Francesco and Simon’s ‘Erlang Programming’. It presents a broad view of much that Erlang has to offer in a way that is very accessible to newcomers. They systematically present what you need to get started in the first three chapters, then explain the concurrency model and the three process design patterns in the next two chapters. The next few chapters of the book dive into the details of various features of the language: records, specialized data types, persistence options. Then you are ready for OTP: the Open Telecom Platform. This is where Erlang really shines and they describe it clearly and concisely. The latter chapters cover various language libraries and features: sockets, the Mnesia database, interfacing with C and Java (elegant!), and the finer points of debugging, tracing, testing, documenting and deploying your application.

    By all means, get all three books: ‘Programming Erlang’ (Pragmatic) by Joe Armstrong, ‘Erlang and OTP in Action’ (Manning) by Martin Logan et. al., and this book by Francesco and Simon. But if you choose to buy only one, I do not hesitate to recommend this one. But do yourself a favor and get all three. Each one offers a different perspective.
    buy this book!
    - Cheers

Leave a Reply