Preface
Erlang has long been a mysterious dark corner of the programming universe, visited mostly by developers who need extreme reliability or scalability and people who want to stretch their brains.
Developed at Ericsson to serve on telephone switching equipment, it seemed like a strangely special-purpose language until recently, when our computer and network architectures came to look a lot more like massively parallel telephone-switching equipment. Thanks to the rise of NoSQL data stores CouchDB and Riak, you may already be using Erlang without realizing it, and Erlang is moving out into many more fields.
Exploring Erlang, if you come from pretty much any background other than functional programming, will require you to clear your mind of many techniques used in other programming languages. Forget classes, forget variables that change valueseven forget the conventions of variable assignment.
Instead, youre going to have to think about pattern matching, message passing, and establishing pathways for data rather than telling it where to go. Erlang programming can feel like making a key whose teeth set the tumblers on a lock just right for the key to pass, or playing pachinko and watching the balls fall through a maze.
Sound strange? It isbut also enjoyable, powerful, and fun.
My first explorations of Erlang confused me and excited me at the same time. Id had some experience with what Id called invariant variables, variables that can be bound to a value only once, in XSLT. That created a lot of headaches for me until I realized I was coming at the problems all wrong, and then it suddenly made sense.
Who This Book Is For
This book is mostly for people whove been programming in other languages but want to look around. Maybe youre being very practical, and Erlangs distributed model and the resulting scale and resilience advantages appeal to you. Maybe you want to see what this functional programming stuff is all about. Or maybe youre just going for a hike, taking your mind to a new place.
I suspect that functional programming is more approachable as a first language, before youve learned to program in other paradigms. However, getting started in Erlangsometimes even just installing itrequires a fair amount of computing skill. If youre a complete newcomer to programming, welcome, but there will be a few challenges along the way.
Who This Book Is Not For
This book is not for people in a hurry to get things done.
If you already know Erlang, you dont likely need this book unless youre looking for a slow brush-up.
If youre already familiar with functional languages, you may find the pacing of this Gentle Introduction hopelessly slow. Definitely feel welcome to jump to another book that moves faster if you get bored. Come back if you find the others go too fast, and feel welcome to use this as a companion guide or reference with the other books.
What This Book Will Do For You
In Seven Languages in Seven Weeks , Bruce Tate suggests that Erlang makes hard things easy and easy things hard. This book will get you through the easy things hard part, and show you a bit of the promised land of hard things easy.
In practical terms, youll learn to write simple Erlang programs. Youll understand why Erlang makes it easier to build resilient programs that can scale up and down with ease. Perhaps most importantly, youll be able to read other Erlang resources that assume a fair amount of experience and make sense of them.
In more theoretical terms, youll get to know functional programming. Youll learn how to design programs around message-passing and recursion, creating process-oriented programs focused more on data flow.
Youll also be better prepared to read other books and conversations about Erlang.
How This Book Works
This book tries to tell a story with Erlang. Youll probably get the most out of it if you read it in order at least the first time, though youre always welcome to come back to find whatever bits and pieces you need.
Youll start by getting Erlang installed and running, and looking around its shell. Youll spend a lot of time in the shell, so get cozy. Next, youll start loading code into the shell to make it easier to write programs, and youll learn how to call that code and mix it up.
Youll take a close look at numbers because theyre an easy place to get familiar with Erlangs basic structures. Then youll learn about atoms, pattern-matching, and guardsthe likely foundations of your program structure. After that youll learn about strings, lists, and the recursion at the heart of much Erlang processing. Once youve gone a few million recursions down and back, itll be time to look at processes, a key part of Erlang that relies on the message-passing model to support concurrency and resilience.
Once you have the foundation set, you can take a closer look at debugging and data storage, and then get a quick look at a toolset that is likely at the heart of your long-term development with Erlang: the Open Telecom Platform (OTP), which is about much much more than telephones.
Some people want to learn programming languages through a dictionary. Heres a list of operators, heres a list of control structures, these are the datatypesand then smash them together. Those lists are here, but theyre in , not the main flow of the book.
The main point you should get from this book is that you can program in Erlang. If you dont get that, let me know!
Why I Wrote This Book
Im not an Erlang expert hoping to create more Erlang experts to get a lot of work done.
Im a developer and writer who encountered Erlang, thought it was the programming language Id been seeking for a long time, and felt compelled to share some of that. Im hoping that the path I followed will work for other people, probably with variations, and that a book written from a beginners perspective (and vetted by experts) would help more people find and enjoy Erlang.
Other Resources
This book may not be the best way for you to learn Erlang. It all depends on what you want to learn and why.
If your primary interest in learning Erlang is to break out of a programming rut, you should explore Bruce Tates wild tour of Seven Languages in Seven Weeks (Pragmatic Publishers), which explores Ruby, Io, Prolog, Scala, Erlang, Clojure, and Haskell. Erlang gets only (an excellent) 37 pages, but that might be what you want.
For an online experience (now also in print from No Starch Books) with more snark and funnier illustrations, you should explore Fred Heberts Learn You Some Erlang for Great Good! , at http://learnyousomeerlang.com/. While much longer than Tates telling, it certainly moves faster and may feel more like an experienced programmers guide to Erlang.
The two classic general books on Erlang are the similarly-titled Programming Erlang (Pragmatic Publishers) by Erlang creator Joe Armstrong, and Erlang Programming (OReilly) by Francesco Cesarini and Simon Thompson. They cover a lot of similar and overlapping terrain, and both may be good places to start if this book moves too slowly or you need more reference material. Erlang Programming goes further into what you can do with Erlang, whereas Programming Erlang provides a lot of detail on setting up an Erlang programming environment.
On the more advanced side, Erlang and OTP in Action (Manning) by Martin Logan, Eric Merritt, and Richard Carlsson, opens with a high-speed 72-page introduction to Erlang and then spends most of its time applying the Open Telecom Platform, Erlangs framework for building upgradeable and maintainable concurrent applications.