Why you should use Elixir & Phoenix in your next project

Whenever I meet another programmer it's not long before I tell them about the wonderful world of Elixir. Usually, their first response is, yeah sounds good, but why would I use it when there are perfectly good technologies like NodeJS, Java, .Net, Ruby and whatever else you can think of. Well, my friend, it comes down to 4 simple advantages: Time to market, Testability, Opinionation, Scalability.



Elixir is a functional language built on top of the highly concurrent language Erlang. If you haven’t heard of Erlang before, it's the language that powers the telecommunications around the world. Concurrency is it's number one feature, though if you’ve ever read any of it you know the syntax isn’t it's defining the attribute. Incomes Elixir, it takes all the features of Erlang and adds better syntax and modern API and Web development features. 




Time to Market

2018 I had the pleasure to work on a startup in the education space. We took an idea to market in 6 months with a tiny team of 3 full-time developers. With no Elixir experience, I was able to go from not knowing how to assign a variable to produce production ready, tested code. It was only possible with the simplicity of the syntax, the help of a senior developer and the straightforward way in which you approach problems in this language. 



It's very rare to release an MVP with such a small team in such a short amount of time, but with Elixir it makes it a whole lot easier. Take for example Ecto, their database wrapper, it handles almost anything you could think of with a wide variety of database vendors, all without writing a single line of SQL. In fact, the only time I ever had to write any SQL was complex migrations, for basic to intermediate migrations you can handle them pretty easily with Ecto, it’s only the more complicated ones that require some actual SQL knowledge. This made it a breeze once we got into production, we could alter the database without much challenge. Ecto is smart enough to handle migrations and rollbacks for you, yes you can run into issues if you don’t do it properly as I did but that's my own fault, not Ectos, so be careful. 




Phoenix is the Ruby on Rails equivalent, it handles a lot of the bullshit of web development. It couples Ecto the database wrapper with a whole bunch of goodies such as models, views, controllers, plugs (handy little connection adapters), insanely high levels of connection concurrency. These are all packaged up in the Phoenix framework, which like Ruby on Rails makes developers lives easier, and project build times quicker. 



Testability

Testing is a massive part of producing high-quality code that won’t blow up when a customer starts to use it. Testing in Elixir is a first class citizen, it comes out of the box, set up you just begin writing your tests. Elixir being a functional language means that it doesn’t need to be mocked, in fact, mocks are highly discouraged unless your testing 3rd part dependencies such as a payment system like Stripe, this was the only time I needed to use mocks for a production system I was working on. For me, this is one of the best features of the language. I don’t have to worry about all the little classes I'm going to have to mock, I just call functions, pass in the right data and assert a response. It’s really that simple. 



Another amazing feature which comes from Erlang, is the ability to run your tests concurrently. Take for example the Ecto library in Elixir, it runs over 3000 tests in a matter of seconds. Testing is not only easy, but it’s fast. 

Opinionation

In the world of JavaScript, there are a million and one ways you can do anything. From the == and the === to the sheer number of frameworks even to do the same thing (React, Vue, Angular and more). In Elixir it's not quite one library for each task, often there's only one in the case of GraphQL but for smaller things, there can be multiple but what you can say is there is almost always the best library/biggest which is commonly used and thus a lot of help on the internet. This is great because it's very easy to find help when the various ways of doing things are limited. 



One of the greatest strengths of the language is its conventions. If you jump on any Elixir Phoenix project you're going to get a similar if not identical structure, but you should always get the same naming conventions. A migration is stored in a certain place with a big long number at the front so you know that it's a migration as soon as you look at it (that's not what the number is for but it helps). If you had the database table user, the model/changeset that checks the data you put in the table follows your rules will be called user, and the context that defines what CRUD operations to be performed will be in the file users. 



In the last 2 years, Elixir has come with an inbuilt code formatter, it can be run from the command line and will automatically format your code to the language standards, this makes it dead easy for a newcomer to follow standards, and it's even better when you don't have to set up linting. 



All these language opinions I find make it easier to pick up and especially easy for anyone to jump in.

Scalability

The biggest upside to Elixir is its scalability. WhatsApp switched to Elixir because it can handle insane numbers of connections without blocking. In a world where CPUs are getting wider with more cores rather than taller, higher frequencies. It becomes even more important that you can harness the power of concurrency. You can even take advantage of this without making any code changes, the more core you have in your laptop the faster your tests will run. Elixir uses Erlang to automatically grab all the available cores and threads and use them. I won't go over all the scalability tests but I'll link to some very famous ones. As a result, some of the biggest companies in the world use Elixir to service millions of customers, companies such as Bet365, Pinterest and Grindr. In the coming years, we’re going to see more and more companies moving to Elixir to take advantage of its highly scalable nature. 



Wrapping up

Elixir isn't the easiest and it's not the hardest to learn, for juniors or people who've spent their lives in OO languages it might be tougher but if I can do it anyone can do it. I was a graduate who had never done any functional programming in my life and I picked it up pretty quickly. 

The community is great, there's plenty of people out there who will help you out. For my the best part about Elixir is the ease in which you can get something quite functional, up and running. It doesn’t take long and before you know it I’ve got an API running performing CRUD functionality with GraphQL, with a login system and an extensive testing suite. This is all thanks to Elixir and the Phoenix framework, which just make a developers life enjoyable. Enjoyable has to be the greatest strength with Elixir, it's not all the features that I’ve mentioned above it's the ease in which I can do things, the joy I get from solving the problems, not re-inventing the wheel. The repetitive tasks, for the most part, are done in an easy way. You’re left with the problem solving, just the way it should be.


Now that I’ve got you all excited to learn Elixir, head on over to Pluralsight. I’m always learning something new and with Pluralsight I can have unlimited access to all things programming. But hold on, it’s not just programming. There’s photoshop, visual communication, manufacturing and design. There's a whole bunch! Sign up today and get a free 10-day trial!



Previous
Previous

Be a rubber ducky, find a rubber ducky

Next
Next

Deliverying a project