Intro
A functional language that runs in the Erlang VM, beam.
It’s fault-tolerant, low-latency, and performant.
It’s popular in applications relating to Distributed Systems, Embedded Systems, data-pipelines, multi-media processing, and web dev with the Phoenix - Web framework for Elixir.
Famously used by Discord for handling messages, media, user-interactions thanks to its high concurrency architecture. For more, see Elixir’s Domain.
Features
Processes
All Elixir code runs inside executable threads known as processes. Don’t confuse these with OS processes. These processes communicate with each other via messages sent between them on different ports.
Fault Tolerance
These Worker processes are often controlled by a Supervisor process, that spins up replacements should one of them fail, making the services fault-tolerant
children = [
TCP.Pool,
{TCP.Acceptor, port: 4040}
]
Supervisor.start_link(children, strategy: :one_for_one)This snippet declares the strategy the supervisor uses, to spin a new worker for each that fails.
Scripts
We can write simple scripts and execute them like most programming languages…
Simply write your code in a .exs file and executes from your terminal using elixir.
Example super_complex_script.exs:
IO.puts("it's as easy as so")$ elixir super_complex_script.exsInteractive Coding
The IEx (Elixir Interactive shell) allows for quickly writing and executing Elixir code in the terminal. This is great for experimenting, trying out language features, or writing small programs to do something on the fly. It reminds me of Ruby’s IRB.
For example:
$ iex
Interactive Elixir - press Ctrl+C to exit (type h() ENTER for help)
iex> h String.trim # Prints the documentation
iex> i "Hello, World" # Prints information about a data type
iex> break! String.trim/1 # Sets a breakpoint
iex> recompile # Recompiles the current projectProject Structure
Read this guide on Mix and OTP
…