Elixir 101
A little bit of history
- Created by José Valim (member of Rails core team)
- Less than 4 years old
- 8K stars on github
- Open source
- Growing rapidly
Language features
- Functional
- Syntax similar to Ruby (No parenthesis hell)
- Highly performant
- Compiles to bytecode and runs in the Erlang VM
- Allows to build distributed fault tolerant applications
- Uses the actor model for concurrency
Erlang ecosystem
- Developed in the 80's for the telecom industry
- Millions of parallel conversations happening at the same time
- Almost zero tolerance for downtime
- It can achieve 99.9999999% of reliability (32 ms per year)
Telecom problems to solve
- Handle a very large numbers of concurrent activities
- Need to perform actions at a certain point in time
- System distributed over several computers
- Continuous operation over many years
- Software reconfiguration without stopping the system
- Fault tolerance both to hardware failures and software errors
- Need to perform actions within a certain time
- Runs in the Erlang VM
- More than 1 Billion users (2016)
- 50 Billion messages sent every day in (2014)
- 70 Billion Erlang messages per second (2014)
- 2 million sessions per server
Garbage collector
- JVM VS Erlang VM
- Java works with one heap
- In Erlang VM there are multiple process, each one with its own heap
Interesting features
- Guard clauses
Interesting features
- Pipe operator
- Pattern matching
Interesting features
- Pattern matching
Interesting features
- Can run comments as tests and generate documentation
Interesting features
- FizzBuzz kata in Ruby
Comparing with Ruby
- FizzBuzz kata in Elixir
Comparing with Ruby
- Execute `spawn` (it will return a PID)
Creating process
- `Send` messages to processes using a PID (not only strings)
- The created process can `receive` messages
- The `receive` method works with pattern matching
- A timeout can be specified
- Execute `spawn_link` to link two processes
Creating process
- If the child process dies, the father will die
- Two linked processes can communicate bidirectionally
- Stands for Open Telecom Platform
OTP
- It's a much more advanced framework to deal with concurrency
- It creates a tree of processes
- It can supervise processes and restart them if they die
Books
QA?
Elixir
By David Molinero
Elixir
- 349