A Love Letter to Elixir
by Daniel Silva
Since I have joined Bitmaker, I have been working with Elixir and I could not be happier. Every new project we start developing at the company is written primarily in Elixir. I am so excited about the language that is now my primary tool for my personal projects as well.
But why? Why do I choose Elixir over Java, Python or .NET when these are industry standard technologies for web development with a huge market demand?
It is the year of 1986 and the first version of Erlang is born. Developed by Ericsson, the language was custom built for their telephony products. Telephony is by nature a distributed system and it must be fault tolerant. You never expect to not be able to make a phone call or a call drop because of a system failure. Erlang was built with these goals in mind and 30 years later we can still see that it paid off immensely. Today, Erlang is widely used for GPRS, 3G and LTE networks all over the world.
Functional programming might a little bit scary at first, especially if you always lived in the land of object-oriented programming. But the truth is even other object-oriented programming languages are starting to get ideas from functional programming (destructuring assignment, lambda expressions, higher-order functions, …).
Erlang and Elixir are both functional programming languages that share a lot in common. Elixir is a superset of Erlang that runs on BEAM virtual machine, just like Erlang. Also, Erlang code is interoperable with Elixir code, this means we can use every function and library available for Erlang directly into our Elixir code. Just for that, Elixir wins over 30 years of software and knowledge built for Erlang.
Another cool feature about Elixir is data immutability. Every single data structure in Elixir is immutable and cannot be changed. When we want to do some sort of transformation on our data, we apply a function to our data and a new data structure is generated by the transformation.
This seems such a simple concept at first but it is really important to avoid some nasty bugs with incoherent data. In other object-oriented languages, it is common to have issues related to mistakenly changing data on a structure that is used elsewhere in our code and we just lost track of it. If the developer is not careful, it is pretty easy to start piling up bugs relating to incoherent data that are fairly hard to find. With data immutability that does not happen because we always know for sure what our data is and it does not change.
Then there is also pattern matching that is another simple concept but immensely useful. Besides allowing us to do quick and easy assignments, pattern matching also allows to easily add a layer of safety to our programming by specifying how our data should be like in functions parameters of functions return values.
Then there are some more advanced features like supervision trees, remote code execution, automatic failover and takeover, … that are built in the language that can be used with little effort in our applications.
And this is just the language. The whole community arround Elixir is one of the most vibrant and enthusiastic I have ever seen. And from the community comes the great Phoenix framework that allows us to build web applications quickly and with great performance! Where can I find another framework capable of handling requests in microseconds?
Because of this, in the last few months we have seen the speed and eficiency that we develop new software is increasing every day. The languague is powerful and empowers us as developers to build quick and well.