Elixir Primer and Resources

History of Elixir

Elixir is a relatively new language, but it has a long history. The history of Elixir starts with Erlang.

Erlang first appeared in 1986 and was designed as a tool for use in building telephony applications, software that runs telephones and other telecommunications equipment. The primary goals in creating the language were to enable high concurrency and high availability in a highly distributed, always-on system.

If you can imagine the throughput needs of a telephone exchange server (hundreds of thousands of concurrent calls) and the consumer demands of a telephone exchange (it must always work, all the time, with no delay), you can imagine the kind of software Erlang must be capable of building.

Fast forward three decades, and think about the needs of highly scalable web applications.

Pinterest, for example, delivers 14,000 notifications per second. Facebook needs to receive updates from and push messages back out to 1.6 billion (With a B!) active users. This kind of high concurrency and high availability is exactly what Erlang was designed for.

And so this old warhorse telecom language has suddenly become trendy and popular again. Except in a new form.

It turns out that Erlang is really hard to read and write. This isn't surprising, since it was developed in the 1980s. This was before "fun to use" was an important consideration in language design.

Erlang isn't well-suited for the generation of developers who grew up on Ruby and JavaScript. Besides usability, Erlang doesn't have all the features that might be needed for modern web applications.

So, in 2012, José Valim created Elixir. Elixir code compiles to Erlang bytecode, and is run on the Erlang runtime. You can even include Erlang code directly in Elixir (somewhat analogously to how you can include JavaScript in CoffeeScript).

Valim was a part of the Ruby on Rails development team, and even authored a book on Rails development. The Ruby on Rails team takes the developer experience very seriously, and that concern influenced the design of Elixir.

The syntax is very similar to Ruby, and is much more readable than Erlang. Besides the easier syntax, Elixir extends the capabilities of Erlang to include (among other things) metaprogramming, polymorphism, and inline documentation.

Brief Introduction to Functional Programming

Elixir, like Erlang, is a functional programming language. This is a bit different from most other languages, which are almost all imperativeand usually object oriented.

Most programming languages have some kind of code-block syntax called a "function". Or, in some object-oriented languages they are called "methods," but everyone knows that a method is just a "function" attached to an object.

But is a function really a function?

In software development, we're used to functions doing something. We call these somethings "side effects."

But in mathematics, functions don't have side effects. You don't define a circle with a function that plots all the points of a circle and also changes the course number for Intro to Hypothetical Geometry.

In math, a function is deterministic; given any particular input x, it will always return the exact output y and not do anything else.

By admitting side effects into programming, we introduce state — the current condition of the running program environment. And the problem with state is that it can change over time.

A variable might mean one thing now, and something else ten minutes from now. And that means that a particular function call with input x might return two different values of y at two different times.

Is that a problem? That depends. None of the most popular development languages are purely functional, so it is clearly possible to build all sorts of things (or, just about everything) using languages that rely on side effects and global state.

However, in a highly distributed, always-on system, this can be a problem. If a system is spread over several dozen (or several thousand) physical computers, how do you propagate changes to global state to all of them?

If a system does go down, how do you quickly restore global state? If a function call might return different values at different times, how can you be sure that the test you run today will still pass tomorrow?

Functional programming seeks to avoid all these problems by being stateless. A functionally-designed program is a collection of functions which are completely deterministic, which means that the system as a whole is deterministic. Given any particular input, the output is guaranteed.

This sort of mathematical purity has long been of interest to academic computer scientists, but the real-world of software development has been largely uninterested — until suddenly, because of the needs of the internet, everyone has become interested.

Functional programming is one of the most important current trends in web application development.

Functional Programming Resources

If you really want to get your head around Elixir, you'll need to get your head around Functional Programming. Here's where to start.

A Bit About Erlang

Elixir programs run in the Erlang runtime environment. You can do a lot with Elixir without knowing Erlang. But if you want to become a serious Elixir developer, you'll also want to become familiar with Erlang.

A Few Erlang Resources

Elixir Resources

Online Resources

The first place to start looking into Elixir online is the official Elixir language site.



  • Phoenix: a web development framework for Elixir. And don't miss this great book on Phoenix co-authored by the creator of Phoenix and the creator of Elixir.

  • Awesome Elixir: community-curated list of awesome projects for Elixir.

  • Elixre: regular expression tester and reference.

Community and Continued Learning

Books on Elixir

Should I Learn Elixir?

If you are interested in working on cutting edge web applications, particularly those that serve large numbers of concurrent users, Elixir is definitely worth knowing.