Elixir in Real Life. My perspective after working with… | by Eduardo Rico | Jun, 2022

My perspective after working with Elixir (and Phoenix) in a real production environment.


About a year ago I came to a great company, my colleagues are experts and the environment is challenging but friendly, and lovely. I am a chemist, I started working with code and scientific computing doing my thesis but I never worked on a big productive project.

When I arrived at this company I started using Elixir because that’s how things were already done, nothing special, it is a language that roughly resembles Ruby (which is a bit like Python) but has another approach, in Ruby everything is an object, EVERYTHING, but in Elixir everything is a function, I was getting into the world of functional programming.
I already knew JavaScript (and specifically React.js which has a lot of functional programming notions) and there were certain things that seemed familiar, however, there are pros and cons of Elixir that I want to talk about.

1. Composition of functions

It is something that seems very abstract, closer to mathematics than to computation, however, it is something that seems, humanly, more natural.

Instead of having a variable with multiple methods, you have a sequence that injects the result of a function to another, an example could be a path in express.js that would be written this way:

It could be written a little more legibly:

In this case, the first would be to use the get method, then to allow the use of cors, then an authentication function and finally the function that returns the information given the previous steps.

2. Pattern Matching

It is one of the features of functional programming that JS has adopted throughout its history, there is not much to say about this pro, surely if you are looking for a programming language like Elixir, you have used or at least heard of destructuring.

It is a clever way to declare variables, however, in Elixir it also works to select a particular function, for example, we have two functions called sum, one of them accepts 2 parameters and the other 3, Elixir knows which function to call given the input parameters, which allows to use it as an “if”.

In the previous functions depending on what parameters we send to the function one or another is executed, the previous function is very basic, however, it allows us to see how powerful this way of making code is.

1. The Pattern Matching

In terms of development, it is excellent, however, when it comes to debugging it is extremely painful, although we can document the functions, the documentation only makes the code more verbose and difficult to read, this would be easier if the language was typed.

2. The error messages

They are simply horrible, one has to spend a lot of time trying to figure out what the message wants to tell us, after some time it becomes intuitive but this makes it not a language suitable for a beginner.

3. The community is great but:

In general, there is little elixir information in productive environments, i.e. it is difficult to find someone who already has good elixir or phoenix experience.

4. The promise of resiliency, speed, and multiprocessing is no longer a differentiator.

Nowadays tools like Kubernetes, gunicorn, and compiled languages like Go and Rust allow us to use concurrency and multiprocessing in a very simple way (depending on what we are going to do). This was a good differentiator of Elixir with respect to other languages like Ruby 10 years ago, nowadays, I think there are better tools to do what once made it famous.

5. Compiled but runs on a virtual machine

The compiler is fast, very fast, however, it could be stricter regarding errors and warnings as in Rust or Go. On the other hand, I think one of the advantages of a programming language being compiled is the portability of the bundle. In this case, it doesn’t matter because you need the Erlang virtual machine to run Elixir. In the end, you don’t manage the processes. However, it makes the CI/CD process more complex in certain senses.

It is similar to Java in that sense, only less robust and only functional, however, it is not a good differentiator because there are languages like Scala or Clojure that are functional, fast, and run on a virtual machine.

I think Elixir is good to learn functional programming because you don’t have to fight with typing and other stuff. If you come from Ruby or Python the syntax is not really a problem, you just have to change the way of thinking, but it is not that complicated.

It is fast in production but it is difficult to debug and complicated to deploy. It also has very little information and few dependency updates, for example, the Ecto drivers for SQLServer.

It does not have any real differentiator, there are many programming languages that use the functional paradigm and that, in addition, are more loved by the community, with more references and more information available.

Anyway, it never hurts to learn something new, I think Elixir is a good challenge to learn.

If you already know RubyOnRails and you want to do something very fast with the same syntax I think Phoenix is the option. In general I think it is much better than ROR and its syntax is refreshing, besides, it has a similar configuration in the project structure, I’m sure you will love it.

News Credit

%d bloggers like this: