Elixir, 7 steps to start your journey

Read this post in Spanish.

Let’s talk about Elixir!

Elixir is a functional programming language created by José Valim to build concurrent and scalable systems. It is defined as:

“a dynamic, functional language for building scalable and maintainable applications”.

https://elixir-lang.org/

Its first version was released in 2012. Since then, new features and improvements have been added until its current version. It is a relatively young programming language that has established itself quickly due to its nice syntax and short learning curve. Also, it is supported by a technology that has been working since the eighties in production systems, the BEAM.

Elixir runs on the BEAM, Erlang’s virtual machine.  

In a later blog post, we’ll go into more detail about the virtual machine. For now, I want to mention a few features that make the BEAM a solid technology and a fantastic choice for system development. For example:

  • It simultaneously supports millions of users and transactions.
  • It has a mechanism to detect failures and define strategies that allow a system to recover from them.
  • It has all the necessary elements to develop a system capable of operating without interruptions or, failing that, with the minimum of them.
  • It allows system updates in real-time without stopping and in an “invisible” way for end users.

Elixir inherits all these properties from BEAM. Adding to it that-the language has a very nice syntax, it is easy to learn, there are many resources (blogs, podcasts, etc), and the community is very friendly. So creating a project from scratch to start practicing requires very little time and effort.

I was introduced to Elixir by chance in 2018. The project I learned it with made me suffer a bit because it was a different experience than what I was used to until then. But once I got into the rhythm, it became pretty enjoyable. Sometime last year, I wondered what would have happened if I hadn’t discovered it by coincidence.

Would Elixir have caught my attention on its own? Is it a recommended option for someone learning to program? Do you require previous experience?

So I posted a tweet asking other developers:

Here are some answers:

It is not easy to reach a definitive conclusion since choosing this language, as the first option will depend on the tastes and experiences of the individual. Some of its advantages are mentioned in the tweet replies, which motivated me to write this series.

Without further ado, I welcome you to the series Elixir, 7 steps to start your journey.

Throughout seven chapters, we’ll talk a bit about history, relevant technical aspects and delve into why Elixir has quickly gained popularity. I will also tell you a little about my experience in the projects in which I have participated.

What topics will it cover?

  1. Erlang’s virtual machine, the BEAM
  2. Understanding processes and concurrency
  3. Libraries and frameworks
  4. Testing and debugging
  5. The Elixir Community
  6. Functional Programming vs. Object-Oriented Programming
  7. My first project with Elixir!

Who is this series for?

  • People with no experience in any programming language looking for an option to explore.
  • People with previous experience in other programming languages who want to experiment with Elixir.

Difficulty level: Beginner

Elixir official documentation:

In each chapter, I’ll share resources to dig deeper into the topics. You can find me on Twitter as @loreniuxmr to clarify questions or continue the conversation. You can also use the hashtags #MyElixirStatus and #Elixirlang  to find other Elixir developers.

Erlang’s virtual machine, the BEAM

Welcome to the first chapter of the series “Elixir, 7 steps to start your journey

I know you’re here because you would like to learn more about this programming language, but before talking about Elixir, we need to talk about Erlang and its virtual machine (VM), the BEAM.

The magic behind the concurrency and scalability of an Elixir system happens in this virtual machine. The Elixir code you write runs on it. Therefore, before addressing the features of the programming language, we must understand its fundamentals.

What is Erlang?

Erlang is a development platform composed of:

  • The programming language with the same name, Erlang.
  • The framework OTP.
  • A virtual machine, the BEAM (Bogdan / Björn’s Erlang Abstract Machine).
  • A set of tools.

It should be noted that when we talk about Erlang, we can refer to the platform as such or simply to the programming language. This is probably familiar to you if you have worked with object-oriented programming. The same thing happens with Java. Java can be the ecosystem that includes the JVM or simply the language. 

For this note, when we mention Erlang, we mean the entire platform. With that said, let’s talk about a bit of history.

Erlang is a development platform created by Joe Armstrong, Robert Virding, and Mike Williams in the mid-1980s at Ericsson’s Computer Science Laboratory to facilitate the development of telecommunications systems.

Currently, it is used to develop distributed, concurrent, scalable, and fault-tolerant systems. And although it refers to telecommunications, it is a general-purpose technology that has demonstrated its robustness in production systems for over 30 years.

If you think about it, most of today’s systems require these characteristics: to be distributed, scalable, concurrent, and fault-tolerant, among others- in addition to being expected to work almost without fail and to be able to recover quickly from any error. For example, WhatsApp. In the few times it has crashed, how long does it take to see bug reports on social media? User complaints are almost immediate. Now, imagine the margin of error in more critical sectors, such as health or the stock market, where the slightest mistake can have serious consequences.

By the way, fun fact: WhatsApp uses Erlang.

But let’s be honest; it’s impossible to build a system that is 100 percent bug-free. What we can do is have a recovery mechanism so that no failure breaks or disables the system. This is what Erlang provides by default, all the necessary elements to create this mechanism and develop systems that:

  • Requires a large number of users and support easily adding more if necessary.
  • Can easily detect and recover from errors.
  • Always responds, even if there is an internal error. This means that the system cannot pause or wait indefinitely since that represents uncertainty for the users.
  • Can be updated without stopping or interrupting user activities.
  • Can be distributed.

All this is thanks to its virtual machine, the BEAM.

What is BEAM?

The BEAM (Bogdan / Björn’s Erlang Abstract Machine) is the Erlang virtual machine where Erlang or Elixir code is executed.

Elixir code is compiled into bytecode files that run on the virtual machine, these files have the .beam extension.

Erlang and Elixir are not the only programming languages that can run on the BEAM. But for now, let’s put that information aside and focus on the general features of the virtual machine.

The relevance of the BEAM lies in the fact that it is responsible for a system being able to comply with all the mentioned characteristics:

  • Manages concurrency and parallelism of a system.
  • Errors have a minimal impact.
  • Manages a recovery mechanism against those errors.
  • It makes the most of the computer’s resources on which the system is running.

These characteristics translate into reliable, highly available, fault-tolerant, scalable, and distributed systems. 

What does all this have to do with Elixir? 

Elixir in the BEAM

As we mentioned at the beginning of the post, Erlang is a platform made up of four elements. One of them is the Erlang programming language, which obviously allows you to write code that runs on the virtual machine. But it’s not the only one. There are more programming languages, one of them being Elixir.

So, why would we choose Elixir?

Erlang, the language, is compatible with Elixir code. This means that what you can write in Erlang, you can write in Elixir and vice versa, with the difference that Elixir’s syntax and toolings feel much more friendly and accessible—allowing cleaner, more maintainable code to be written and with a short learning curve.

Although, of course, it will always depend on the tastes and experiences of each person. The characteristics of Elixir have made it more and more popular by developers, with many

resources created around it.

In short, with Elixir, the power of BEAM is harnessed through a friendly programming language, a fantastic community, and plenty of resources like documentation and tutorials, allowing you to build projects in no time and experience all of its features.

And this is all thanks to Erlang processes, which we’ll look at in the next chapter. 

Next chapter…

I know you’re eager to see the code. Don’t worry, in the following note, we’ll go deeper into what Erlang processes are and how to implement concurrency using Elixir.

Documentation & Resources

Technical advisor: 

See you in the next chapter!

Keep reading

Technical debt and HR – what do they have in common?

Technical debt and HR – what do they have in common?

At first glance, it may sound absurd. Here we have technical debt, a purely engineering problem, as technical as it can get, and another area,...

Blockchain Tech Deep Dive| Meaning of Ownership

Blockchain Tech Deep Dive| Meaning of Ownership

What does 'ownership' really mean in the era of rising prominence of digital assets Let's explore this in third instalment of our blockchain blog series.

Blockchain Tech Deep Dive | Innovating with Erlang and Elixir

Blockchain Tech Deep Dive | Innovating with Erlang and Elixir

We're exploring why Erlang and Elixir are a good fit for innovation in the ever- growing blockchain space.