Despite being a relatively young language, Elixir already has a wealth of learning resources available including tutorials, screencasts, and books. A while ago we looked at Programming Elixir, which serves as an excellent introduction to the language. Written by Dave Thomas, Programming Elixir is probably one of the best ways you can get your feet wet with Elixir.
Elixir in Action is another introductory guide to Elixir that assumes no existing knowledge of Elixir, Erlang, or functional programming. However, whilst Programming Elixir is really for newbies to the language, Elixir in Action is like the next step in your progression to becoming an Elixir developer.
Elixir in Action is written by Saša Jurić, an experienced Elixir and Erlang developer who has worked on many high-volume, concurrent server-side systems.
Elixir in Action opens with a thorough introduction to the building blocks of the language. It introduces you to the main highlights of the language without getting into the weeds of explaining the very basics of programming.
First we look at using
iex so that the reader has a place to experiment with code snippets from the book. There’s nothing quite like running the code yourself to understand what’s going on when reading a programming book.
Organising code into modules and functions is covered next, as well as some aspects of programming languages that readers from other languages might not be familiar with such as function arity.
The types of Elixir get a whirlwind tour. Explaining the types of a language should be probably be kept to a minimum because that type of stuff is better served by documentation and it would take forever to recreate a reference guide to the language.
Next we look at pattern matching. This is a bigger section that covers many of the wonderful applications of pattern matching. Pattern matching was one of the things that really kept me interested in Elixir and so it’s understandable that this would get good treatment.
This section also covers recursion as it might not be something the reader is familiar with, and there is also a small section on conditionals, highlighting the fact that conditionals in Elixir are not widely used.
Finally we look at data abstractions and briefly protocols, something that is interesting but probably not very important if you are just getting started with the language.
The next big section of the book covers OTP. For me, OTP is really the reason why I’ve decided to invest my time into learning Elixir.
Building on the foundation of Erlang and OTP enables an incredible amount of opportunity that you just don’t have in other languages.
First we look at processes as the basic unit of concurrency of Elixir and how we can move code into isolated process that can run in parallel.
Next we look at the abstractions of Elixir, primarily GenServer. One of the best bits of the book for me was when Saša has you walk through developing your own version of GenServer. For me, this is really where things started to fall into place.
Finally we look at supervisors and how we can build fault tolerant applications using supervision trees.
The final section of the book looks at the practical steps required to ship an Elixir project. An important consideration when investing your time into learning a new language is how you get your code from development to production. It doesn’t matter how good the language is if it doesn’t have a strong deployment story.
This section covers building an OTP application, and how the application behaviour allows us to start and stop the application as a single unit.
To manage the dependencies of the application we need to turn to our old friend Mix once again, and finally Saša talks about building and running a distributed application. This is probably something that the reader has never done before, and so I found this section to be particular useful for filling in the blanks of my understanding of how the Elixir deployment story should unfold.
Elixir in Action is a great book if you have little to no experience in Elixir, Erlang, or functional programming in general as it covers every thing you need to know a a beginner in all of these topics.
Throughout the book you work on an ongoing project that you slowly refactor as you learn new techniques. This really encourages the reader to write the code and get a better understanding of the main principles of writing good Elixir code.
All in all, I would highly recommend this book if you are looking to learn Elixir!