Elixir the return of Erlang

I was recently put on a job that required a web stack that required bulk imports and then a sorting algorithm on huge amounts of data. Originally it was planned to be a .net core running on azure with a react front end. Having used .net quite a bit I was excited to use it, but having recently going to a Mac and the company using macs extensively meant that .net core although great would mean a lot of the entity framework that we needed wouldn’t be available, this was kind of a deal breaker. In comes Elixir, being fresh out of uni I had never touched a functional language before. For that matter I hadn’t really touched anything that wasn’t a derivative of C! I took one look at the code and thought what on earth is going on. Arrows everywhere, minimal variables, functions doing strange things, underscores everywhere, more arrows. I freaked out a bit, it took maybe a day to go back and try again. Now for the people who don’t know elixir is a language built on top of the Erlang vm. It provides extremely robust, crash recovering highly paralyzed applications. Being only a couple of years old meant that the tutorials and the help was pretty limited but there are some great tutorials and a fantastic community on stack overflow. I asked many questions which were all answered extremely quickly and with a lot of detail, which is very welcome when your coming from an OO background.

 

What makes elixir so awesome?

 

First of all, concurrency. If you’ve done any concurrency in a traditional OO language then you know the pain of concurrency, managing race conditions, locks and that one in a million bugs that happen can make adding concurrency a nightmare. Elixir fixes all this by making all variables immutable, this immutability means that each thread when reading a variable will always be the value that you think, because each time it’s updated it has to be assigned a completely different variable. This concurrency becomes a breeze in comparison. Elixir also has this concept of supervisors which watch your app and when it crashes it will start it back up, this was originally from Erlang in the telecommunications field to reduce downtime to next to zero. All these features make it highly scalable, it can be coupled with the excellent Phoenix framework which gives an elixir code base an MVC framework. You can use libraries such as Absinthe to integrate GraphQL. I’ll be doing another blog post on my experience with GraphQL. I found piping to be one of the coolest things about the language, being able to get the result of one function and directly pass it to the first argument of another function, think copy and paste for functions.


 

My experience with Elixir.

 

The power of Phoenix is apparent when I had to write crud functionality for my web app, I simply ran a few terminal commands, added a couple of methods and hooked it up to the database which was simple. After the learning curve you can set up a crud application in under 30 mins that can actually write to a real database from GraphQL queries and mutations. This ease of use (once you understand a bit about it) makes elixir amazing for setting up an api layer for your data. My next step will be to hook up the react front end to the elixir api so read and writes can be a breeze.

 

Where to learn Elixir.

 

Pluralsight is an okay resource, there are three courses you can follow, but the best resource that I found most helpful are EQuimper’s React native, elixir instagram clone on YouTube and the crud tutorial by Tensor Programming really explained how to hook up basic crud functionality with GraphQL and Elixir. I would also highly recommend the docs for both Elixir and Phoenix as they are quite helpful, written quite well.

 

Go learn it

 

Honestly just give it a whirl, it's extremely hard to wrap your head around especially for me, but if you have used Ruby or other functional languages you will pick it up much faster, even if your an ES6 or higher JS programming. JS is starting to move towards that functional paradigm. It will take you awhile to get it, but I promise you, it will pay dividends even if you never use it, you will gain an appreciation for the way functional programming works and how theres not just the OO way like us recently graduated programmers believe.


 

Tensor Programming: https://www.youtube.com/channel/UCYqCZOwHbnPwyjawKfE21wg/featured

 

EQuimper: https://www.youtube.com/channel/UC7R7bcH9-KEBDiGNP1mZnmw

 

Previous
Previous

Mac OS & Apple in general

Next
Next

C# the best language that not enough people use