I recently had the pleasure to read “Functional Web Development with Elixir, OTP, and Phoenix” by Lance Halvorsen. As a fan of Elixir and Phoenix, I thought I should take some time to write a constructive review of the book so that others who are looking for a good book on this very topic can choose for themselves.

Prerequisites:

The book will not teach you Elixir or Phoenix. It assumes you have some knowledge of both. I felt the same. To get the best out of this book, you should have some familiarity with both Elixir and Phoenix. Although, there are numerous resources on these topics, I would recommend the below three —

Programming Elixir 1.6 by Dave Thomas — https://pragprog.com/book/elixir16/programming-elixir-1-6

Programming Phoenix 1.4 by Bruce Tate, Jose Valim, and Chris McCord — https://pragprog.com/book/phoenix14/programming-phoenix-1-4 (currently, the book is in beta release). You could as well use the 1.3 version.

The Little Elixir & OTP Guidebook by Benjamin Tan Wei Hao — https://www.manning.com/books/the-little-elixir-and-otp-guidebook (optional to read this book but excellent one)

What’s good about the book:

In this book author took a different apporach to write web applications. Whereas most web applications are stateless and surrounds accross some kind of database for state management, in this book author has maintained state in application without using any database. The application has been developed in bottom up fashion keeping the business domain logic separate from web framework’s own imposed domain logic. Because of that the application (in this case a game) itself is independent of the Web layer, can be independently tested and run even without the web layer.

The clarity of presenting information in the book is remarkable. Author has taken great care to choose the data structures judiciously, present each module/function/data stuctuture step by step in such a way that can be easily understood, implemented, and tested in isolation. I have to say very few book can present such complex topic with this much clarity.

The book is divided into three parts —

Part 1 is where the game application is developed with all it’s data structures and business logic. A state machine has been developed to keep track of the application states. At the end of part one, it’s an independent application that can be run and tested from iex.

Part 2 is where OTP comes into picture for two reasons — fault tolerance and concurrency management. Author did a pretty good job describes necessary concepts of GenServer/Supervisor/Application behaviours and implemented the concepts with great clarity.

Part 3 is finally where author puts the Phoenix Web layer on top of the OTP application developed until part 2. I have to say even though all the concepts of Channel and Presence were presented with care and good explanation, I am still a bit disappointed at this part. I would hope for a full blown Phoenix application with frontend views and templates. But that was not the case. Rather, author implemented the backend code and verified the implementation worked from browser console. In a book of Web Development that is something that disappointed me. Also, there was no real code to Authenticate users on Channel, instead author referred to Chris McCord’s book mentioned above. I had problem some running some code from the book as is but this may be due to version difference — I used Phoenix 1.4 whereas the book covers 1.3.

What could make it better:

I think the below two changes to the book’s content can help further excel this book and make it more complete and independent —

Full-blown Web Application with Authentication — Turn the game application into a full blown web application with authentication on Channel and add frontend code with views/templates .

— Turn the game application into a full blown web application with authentication on Channel and add frontend code with views/templates Umbrella App — Instead of adding the backend OTP application as a dependency via mix.exs as done in the book, I think a demonstration of a umbrella application would be a better fit.

I would also include a chapter on testing but I think Chris McCord’s book does a pretty good job on that.

Application Code:

Finally, I have written the application code in the book as I read it. If anyone is interested, the code is available here on my github —

Overall, I am very happy that I encountered this book. I hope this review will encourage Elixir/Phoenix newbies to pick a good book on this topic.

For more elaborate and in depth future technical posts please follow me here or on twitter.