Elixir lessons
Functional, scalable (Erlang VM)
Elixir was designed in 2011 by José Valim, built on top of the Erlang virtual machine. Erlang is a platform developed to run telecom switches and has proven itself in systems that run uninterrupted for years; Elixir offers this power with a modern and readable syntax.
Elixir's main difference is its concurrency model. The program runs as thousands or even millions of lightweight processes; these processes do not share memory, they send messages to each other. If one process crashes, the others are not affected, and a supervisor restarts it. That is why Elixir systems are designed as "fail-safe" systems.
It is a functional language: data is immutable, state is not updated in place. For those coming from object-oriented languages, this requires a mental shift, but in concurrent systems, it eliminates a large portion of error sources right from the start.
- •→
Introduction to Elixir
First step into Elixir, a functional language running on the Erlang VM: printing with IO.puts.
- •→
Variables
Value binding with = and the concept of immutability.
- •→
Data Types
integer, float, string, boolean; interpolation (#{}) and text↔number conversion.
- •→
Operators
Math (+ - * / div rem), comparison (== < >), and logic (and or not).
- •→
Strings
Concatenation (<>), length (String.length), case conversion, and search.
- •→
Lists
List creation, element access (Enum.at), length, and appending (++).
- •→
Conditions (if / else)
Decision making with if...do...else...end and logical operators.
- •→
Iteration (Enum)
There are no loops in Elixir; iteration is done using Enum.each, Enum.map, and Enum.sum.
- •→
Functions
Anonymous functions (fn -> end, call f.(x)) and module functions (def).
What you will learn
- Printing output with IO.puts and pattern matching assignment
- List, tuple, and map data structures
- Writing functions and defining multiple bodies
- Chaining transformations with the pipe operator
- Processing collections with the Enum module
- Setting up flow control with case and with
Who is this for?
- Those who will write services handling a large number of concurrent connections
- Developers building real-time applications or chat systems
- Those who want to use functional programming in a production environment
When to use?
Elixir is very powerful for real-time applications, services carrying numerous open connections, messaging systems, and backends that need to run uninterrupted; developing web applications with the Phoenix framework is also efficient.
It is not suitable for intensive numerical computation, machine learning, and desktop applications. For a small corporate website, PHP or Node.js is more practical in terms of ecosystem and workforce availability.
Frequently asked questions
What is the relationship between Elixir and Erlang?
Elixir runs on Erlang's virtual machine and can use Erlang libraries directly. So the infrastructure is the same, but the syntax is different. Elixir's syntax is inspired by Ruby and seems more readable to most people than Erlang.
Why is the equals sign a match instead of an assignment?
In Elixir, the equals sign matches the pattern on the left to the value on the right. If the left side is a variable, the value is bound to it; but if you write a tuple pattern, the structure is expected to match, and if it doesn't, it raises an error. This is the most fundamental tool for destructuring data.
What is the difference between a process and a thread?
Elixir processes are not operating system threads; they are very lightweight structures managed by the virtual machine and take up just a few kilobytes. That is why it is possible to run millions of processes on a single server. Since they do not share memory, deadlock issues do not arise either.
What does the pipe operator do?
It passes the output of a function as the first argument of the next function. Instead of nested calls, it allows you to write a chain read from left to right; this operator gives Elixir code its characteristic look.
Summary
Elixir combines Erlang's proven resilience with a modern syntax and stands out in systems requiring high concurrency. In this course, we progress from pattern matching to the pipe operator and the Enum module.