Introduction to Erlang and Elixir

Introduction to Erlang and Elixir

Elixir is a fast, dynamic and scalable language which is fast becoming adopted by the startup crowd and established businesses alike for production applications.

Pinterest, Brightcove, Discord, and Canvas, to name a few, all run on Elixir, which in turn leverages the low-latency, fault-tolerant Erlang VM, meaning complete access to the Erlang ecosystem used by companies such as Heroku, WhatsApp, Klarna, and Basho.

Starting with this tutorial, you'll learn the fundamental knowledge to get yourself started in Erlang and coding with Elixir.

What's the Syntax Like?

The syntax is functional and promotes a short, fast coding style, which allows users easy abstraction to their data:

def serve_drinks(%User{age: age}) when age >= 21 do
# Code that serves drinks!
end
serve_drinks User.get("John Doe")
#=> Fails if the user is under 21

Can It Scale?

Affirmative; Elixir was built with scalable, distributed systems in mind.

Elixir features threaded execution (referred to as processes) in an environment in which multiple processes can communicate with one another via messages.

These light-weight threads can be run in the hundreds of thousands concurrently. Elixir's excellent garbage collector works for each isolated thread, ensuring performance is optimal system-wide and preventing resource lock-ups.

Fault Tolerance

Elixir has Supervisors which can restart parts of your system if things go wrong and revert your system to an initial state that is known to work.

You can run the tests in parallel by setting async: true. In this setting, Elixir uses as many CPU cores as possible.

Meanwhile, assert can check for assertion failures in your code. Those features are built using Elixir macros, making it possible to add entire new constructs as if they were part of the Elixir language itself, meaning total customisation for whatever productivity (unit testing in this case) you may need.

More to Come!

Elixir is a powerful and versatile language used by some of the biggest apps in the world right now. Its fast compile times, light-weight threaded processes, extensibility with DSL modules, and fault tolerance provided with Supervisor make it ideal for any serious web development team. Clearly, when Elixir is fully utilised, there are massive gains to be made.

In the next part, we will continue on the available Data Types of Elixir and how to write more code, and we'll finally get down to compiling it!