Elixir for Python programmers

As you may know, Python is my language of choice. Python is the first language I learned, after a careful selection, more than 10 years ago and it's almost always the language I use at work.

I know other languages too and tried out some more, but I never use them, since I don't need to. The exception is JavaScript for frontend development, as there's no choice (ok, there are some choices, but they are complicated).

Python is so simple to use, effective, omnipresent and well-supported that I don't have to look at other languages. It has at least one good library or framework for each domain, so I can always be sure that I don't have to start from zero. Backends, embedded systems, web apps, desktop apps, even Android apps. Because Python is Python, there is an implementation for any kind of environment, so it's possible to work with other languages' ecosystems in Python.

Having mastered the powerful metaprogramming capabilities offered by Python, I can generalize a system, use metaprogramming and be finished in much less lines than in any other language I know.

Programming in Python was so good it started to get boring. I did try some languages here and there, but nothing stuck. I had to wait for Elixir to find something interesting enough.

Elixir is an high-level functional language that compiles to Erlang. Erlang has been around since 1986, and it's a language designed with a specific domain in mind: telecommunications. Erlang turned out to be well capable outside of that too, and with modern stacks relying on many small components, Erlang started to become an interesting choice. Elixir made it also pretty.

Elixir has macros, which are a rougher form of metaprogramming, but also more powerful. Python's metaprogramming can go a long way, but there are structures that can be simplified only with a macro.

Elixir has Phoenix, one of the most advanced web frameworks out there thanks to the builtin websockets capabilities. The live view library, a recent addition to the Elixir ecosystem, allows to use websockets and Elixir instead of AJAX, made possible to write web applications without writing any JavaScript. Python has Django and while Python people might be more than happy with it, I dread it, since it forces you to make things in the Django way and only that way. Phoenix on the other hand, stays more out of the way.

Elixir has Plug (http servers) and Ecto (ORM). They are not part of the standard library, but they are mantained by the Elixir team. Having standard libraries for common functionalities means that you don't have to learn 4 different ones for the same job. There might be the case where these don't fit a project, but the developers were thoughtful enough to make them configurable and reusable. To be a bit more technical, Plug and Ecto are mostly sets of macros and interfaces, so they are incredibly reusable. In Python only requests has achieved a similar status; for http servers there are plentiful frameworks each with its own implementation. There are least four major ORMs (Django's, SqlAlchemy, Peewee, Pony).

Elixir compiles to Erlang. Erlang runs it's own virtual machine, the BEAM. The BEAM restarts by itself in case of an error, supports distribution across nodes and concurrency. It has ETS and other mechanism to store data in-memory, pretty much like having a built-in redis. There are other features, but these are the Python painpoints when deploying an app.

Because of the BEAM, Elixir can be deployed without docker, removing a level of complexity from the stack without any downsides. Python without docker, it's almost a suicide.

As a functional language Elixir excels at handling data. If you have a code base with many configuration options that have to be passed around, Python becomes easily cluttered and there's no elegant way to handle it. Elixir has a pipe operator, which makes function chains easy to read. You don't see function chains often in Python, but when they are there, they are ugly and there's nothing you can do about them.

Elixir has other features as well, but these are the ones that make an actual difference when comparing it to Python. It has more concepts and more complexity and it's harder to learn and master. So far that has been the only downside that affects my work.