[001.1] Introduction to Elixir

Introduction to Elixir
[02.13.2017]

Welcome to the first episode of DailyDrip's new Elixir topic. In this series,
we'll walk through learning Elixir from the ground up. Once we've got a firm
footing in the language, we'll move on to building a large-scale production web
application using the Phoenix Framework. We'll also explore a variety of other
topics as we go.

What is Elixir and why are you interested in learning it?

In the words of the Elixir website, Elixir is a dynamic, functional language
designed for building scalable and maintainable applications.

It leverages the Erlang Virtual Machine, which has been used for building
high-traffic, low-latency applications ranging from telephone switches to the
WhatsApp backend and Heroku's routing layer.

In general, I find Elixir interesting for three reasons:

I find the Actor Model of computation very compelling, and Erlang's where it
has had the most time to develop.

Since it's built upon the Erlang VM, you can use it to write extremely
reliable, distributed, concurrent systems.

I find the syntax pleasant, and the tooling outstanding.

I've been using it now for over three years and it has been an amazing
experience that I'm eager to share.

Who am I and why am I qualified to take you along as I learn it?

My name is Josh Adams. I was the CTO of a software development consultancy,
Isotope11, for nearly a decade. I've built large-scale systems in everything
ranging from Ruby and JavaScript to Erlang/Elixir and Java. I've built financial
systems that handled billions of dollars worth of transactions each year and
search systems for government agencies. I've also taught people Elixir for three
and a half years, and built a few production systems with it.

Assuming you're convinced by all of this, let's get started learning.

Erlang

Installing Erlang

The only prerequisite for installing Elixir is Erlang, since Elixir runs on the
Erlang VM.

Once that's done, you can use asdf to install all kinds of programming
languages. They each have plugins. To install the asdf-erlang plugin, run the
following:

asdf plugin-add erlang https://github.com/asdf-vm/asdf-erlang.git

Then you can install it with:

# List all of the versions of Erlang available:
asdf list-all erlang
# As of this writing, 19.2 is the latest release. Install it:
asdf install erlang 19.2
# To make it the global default version of Erlang:
asdf global erlang 19.2

Verifying your Erlang installation

You can verify that the installation worked by entering an Erlang Shell. At a
console prompt, type erl and you should be greeted by something that looks
like this:

If you would rather use asdf, you can first install the asdf-elixir plugin:

asdf plugin-add elixir https://github.com/asdf-vm/asdf-elixir.git

Then install Elixir with:

# List all of the versions of Elixir available:
asdf list-all elixir
# As of this writing, 1.4.0 is the latest release. Install it:
asdf install elixir 1.4.0
# To make it the global default version of Elixir:
asdf global elixir 1.4.0

Firing up iex

To verify that your Elixir install was successful, type iex. Assuming you did
everything right, you should be greeted with a prompt that looks like this:

What is the Actor Model?

I had a subscriber ask me for a succinct explanation of the Actor Model.
Without going into it too deeply, I'd describe it thusly:

An actor is an object that has its own lifecycle and lives concurrently. An
actor communicates with another actor by placing a message in his mailbox. The
second actor can then read the mailbox in his preferred order, and respond to
the messages at his leisure. This is a large part of the Erlang 'shared nothing'
model, and one of the core concepts that leads to its fault tolerance and ease
of distribution.

sign up for full access

Meet your expert

I've been building web-based software for businesses for over 18 years. In the last four years I realized that functional programming was in fact amazing, and have been pretty eager since then to help people build software better.