Why the Elixir language has great potential


As a developer I think it is important to stay up to date with new developments. But mostly I love learning new things ;-) This means to be on the lookout for current trends in the tech industry, guessing their potential and trying them out. Sometimes I’m right. For example: A few months ago, adopting GraphQL turned out to be a good guess.

Elixir

One development that kept me busy next to work for the last few weeks was the Elixir language. My background is for the biggest parts in PHP and Javascript. Learning a programming language that is dynamic, functional, immutable, and supports concurrency and pattern matching can be mind bending. But apart from being a modern language, Elixir intrigues me because it…

  1. Compiles to Erlang
    Running on the battle tested Erlang VM is a great choice because its built-in support for concurrency, distribution and fault tolerance. Before looking into Elixir I wasn’t aware how versatile the Erlang VM is and how much it can simplify a tech stack.


    Source

  2. Quality of libraries
    For all my needs so far, I found some library. The quality and maturity of libraries surprised me. For example: the web framework Phoenix, the database abstraction Ecto and the GraphQL library Absinthe. Many more libraries can be found on the package manager hex.

  3. Path for scalability
    Premature optimization is costly. Rewrites caused by quick and dirty work are as well. Thanks to message passing and processes of Erlang there is actually a very nice path for scaling from small to large while reducing waste:

    1. Design your code around processes
    2. Separate these processes into OTP apps
    3. When an OTP app gets too much load, move it to its own node on better hardware

    Source: Learn Phoenix episode “Scaling Phoenix”.

  4. Reliability and resilience
    Contrary to processes in other programming languages, a process that fails in Erlang doesn’t kill the whole application. If a process dies it can be restarted by a supervisor. Organising an application in supervision trees enables building very reliable systems, containing failures within each component. Erlang is known for it’s Let It Crash philosophy.

  5. Performance
    So far I’m very happy with the speed of Elixir/Erlang. Reading about sub-millisecond response times and scaling to 2 million active websocket connections on one server lets me not worry much about this topic just yet.

    Especially when compared to PHP, Elixir comes with great performance. Being able to handle so many websocket connections enables a whole different user experience for web and mobile apps. I’m looking forward to using Elixir with GraphQL subscriptions.

  6. Industry adoption
    Although Elixir is quite young, I was glad to see usages by Pinterest, Bleacher Report, Brightcove, and more and more).

The Elixir Language

Why do functional programmers homeschool their kids?
Because they hate classes

The creator of Elixir is the well-known Rubyist José Valim. The language is influenced by Ruby which makes it subjectively nice to read. I don’t want to go into the language in detail, as other people did this already much better than I could do.

What I wanted to highlight is the usefulness of the pipe operator |>. It works just like the unix pipeline and shuffles the return value of function A into the argument of function B. Instead of writing b(a()) you can write a() |> b().

There are many more things I like, for example pattern matching, the built in Stream module, extensibility via macros and protocols, documentation in markdown format, shared nothing concurrent programming (actor model) and much more.

Tips for learning Elixir

Coming from object oriented programming languages it wasn’t easy to unlearn patterns I practiced for years. But well worth it. How to get started?

Screencast series

I’m a big fan of screencasts. I like the combination between seeing code and hearing explanation at the same time. Luckily I found two nice screencast series about Elixir and Phoenix:

I also saw that there is DailyDrip Elixir which I’d like to watch in the future.

Exercises

Just watching screencast series won’t teach you a language. Practice is important. One way to do this, are the exercises on exercise.io. These exercises are small, fun and teach a lot about the language. Reading solutions of other people after submitting your own is a great way to learn about alternative and maybe better code.

Books

Although I haven’t gotten the chance to read these books myself, I heard good things about them:

Elixirs future?

Who knows. From what I see now, Elixir, although young, has great potential to become mainstream. It enables creating fast, reliable and concurrent modern applications with high productivity. I plan to use Elixir in 2017 at least for some side-projects.

Related Posts

Learning How to Learn – Online Course Notes

My notes for the online course “Learning How to Learn”.

Tips for making screencasts for presentations

As an alternative to live demos you can play screen casts during your tech talk.

Trust and Integrity

My notes for the Speed of Trust by FranklinCovey.

NodeJS: Factory Function Pattern, Dependency Registry and Hot Reloading

This article shows how to combine Factory Functions with a rapid feedback loop using hot reloading.

Better back swiping with the React Native Navigator

Swiping back works only close to the edge by default which can be hard to accomplish. It is easy to optimize this.

How to keep plugins when updating PhpStorm

When updating PhpStorm my plugins seemed to be gone, but you can easily move them over.

Command duration in fish shell

Display how long the last command took and notify when a long running command is finished.

ES6 in Node and in your Browser with Traceur

How to use Google traceur to transpile ES6 javascript to ES5.

PHPUnit find slow tests

When optimizing your testsuite it can be handy do find out how long each test takes to run. It would be nice to have a list of and how many seconds they took.

Remote debugging for PHP cli scripts

Enable remote debugging for your console PHP scripts without much fuzz.