Elixir Logo

If you’ve read any significant amount of my blog you’ve probably realized that I’m fascinated with programming languages; more precisely the syntax, the community, and the purpose of the language. Elixir happens to be one of these languages that has recently caught my attention.

I love the ideas functional programming brings and how you to solve problems as a result of those ideas. One of the things that functional programming is helping people to solve is how to get the most out of systems that have multiple cores. Most applications nowadays are written to use a single core with a way to achieve multi-core processing through the use of threads. The downfall of using threads is that it opens up issues due to mutable state and deadlocks. To use threads in most languages is not an easy straightforward process; this is where Erlang comes into play.

Erlang

Erlang is a language created in 1986, which would make the language about 27 years old. So why do we care about it and how does it relate to Elixir?

Erlang has been used for sometime in systems that need high reliability. Some companies have reported to use Erlang in systems that have been able to achieve a reliability of nine “9"s. You can find Erlang still used in many online services and software for example: Databases like CouchDB and Riak, and at places like Facebook and Github.

One of the strength of Erlang is support for concurrency. Erlang is able to create lightweight processes without shared state, this allows you to divide up your workload into individual processes which support being run on multi-core systems. Erlang’s concurrency implementation is the Actor model.

Elixir is built on top of Erlang, so all the great things that you find in Erlang you will be able to use in Elixir. The only exception is, in Elixir the syntax is more like Ruby.

Elixir

Elixir takes aspects of Ruby and other modern languages to offer a better syntax for working on the Erlang VM. Elixir also adds some unique syntax of its own.

Elixir has all the common things that you would expect from any language, so I will show you some of the exciting parts of Elixir.

Pattern Matching

In Elixir, the = doesn’t refer to assignment as in other languages but it’s used for pattern matching. Pattern matching is used all over the place for various things. One use case is for functions, based on the input, you can match what you want to happen. Think switch statements on steroids!