Elixir
Do we just follow the hype?
Background
- 1.5 year maintaining a legacy Java web application
- 1.5 year creating a Ruby web application
- 3 years maintaining legacy Ruby web applications
Most of my experiences are about working with old and crappy systems
Painful parts
Mutability/IMpurity
- You can reopen classes
- You can include modules
- You can define callbacks
- Static variables
Hard to follow / resonate about code. Older the system, worse it is.
Painful parts
Concurrency (lack of)
- Ruby is slow
- It's a pain to manage threads
- Usage of background jobs as a workaround
We more and more need to talk with different APIs to find the best result for the customer.
It's really hard to do it in a safe and concurrent way.
Painful parts
ActiveRecord (ORM)
- High coupling between business and DB
- DB queries/commands triggered implicitly
- Slow tests
Database available everywhere
Solutions?
Golang
+ concurrency
+ speed
Wasn't convinced at all. It was really fast but all the rest: code, community mindset, Go principles didn't match with me
- code readability
- lack of generics
Solutions?
Erlang
+ concurrency
+ speed
+ immutability
Was totally convinced but I tried to read some book and no way to understand how it really worked / how to use it
- syntax
- learning curve
Solutions?
Elixir
+ concurrency
+ speed
+ immutability
Was really convinced but was a bit worried about the fact it was really young.
+ syntax
± learning curve
± really young
Erlang
History
- Old language (1986)
- Created by Ericsson
- Aim of improving the development of telephony applications
- Functional
- Concurrent
- Distributed
- Fault-Tolerant
Erlang
Functional
- Immutability
- Pattern-Matching
-module(fact).
-export([fac/1]).
fac(0) -> 1;
fac(N) when N > 0, is_integer(N) -> N * fac(N-1).
Erlang
Concurrent
- Actor model
- The language name them Process
- Each process has a state
- Each process can receive messages
- Each process can reply to messages
- Process has to be known to be accessible
Erlang
Distributed
- Each Erlang system running is called a node
- Connection between node is down on first call
- Messages between nodes are transparent
Erlang
Fault-tolerant
- Supervision tree
- Tree containing supervisors and workers
- Workers are processes, they do the work
- Supervisors monitor workers health
- Supervisors decide the restart strategy when a worker die
Erlang
Fault-tolerant
S1
S2
S3
S4
S5
P1
P2
P3
P4
Erlang
Why is it still so confidential?
- Steep learning curve
- Different way of reasoning about our apps
- Documentation lightweight
- Community not easily reachable as beginner
- Not a lot of communications
- Syntax hard to understand for most developers
Elixir
History
- New language (2012)
- Created by José Valim
- Based on the ErlangVM
- Aim of adding a different language construct
- Aim of having an excellent tooling
- Aim of having accessible documentation
Elixir
Erlang Virtual Machine
- Elixir is a language running on the Erlang VM
- It can interoperate with Erlang packages easily
- It gives access, for free, access to all the Actor & Supervision tree
Elixir
Syntax
Erlang syntax was one of the tedious part for most of the developers .
Elixir brings a more conventional syntax, looking a lot like Ruby
defmodule Fact do
def fact(0), do: 1
def fact(n) when n > 0 and is_integer(n) do
n * fact(n - 1)
end
end
Elixir
Features
- Macros: most of the language is built on top of it
- Protocols: a bit like an interface
- Doctests: doc examples are executable
- Mix: a task runner, everything use it
- Resources: Lot of documentation, starter guides and books
Elixir
Why people use it instead of Erlang?
- Power of the Erlang VM
- Syntax easier to grasp than Erlang for most devs
- Learning curve
- Good documentation (language & packages)
- Good starter guides (explained in a way people not familiar with functional programming can understand)
- Books with concrete web examples
- Communication (blog posts, conferences, books)
- Community (lot of friendly people on Slack and IRC)
Phoenix
What are the promises?
- Web framework
- Fast
- Strong focus on maintainability
- Decoupling of business logic and storage
- Powerful pipeline of middleware
- Easy communication through Channels (JS, iOS, ...)
Conclusion
- Technology built for concurrency, fault-tolerance
- New/Easier syntax for a battle proved technology (beneficing of years of apps running in production: WhatsApp, Text messages,...)
- Some new features added on top of Erlang (protocol, macros)
- Full interoperability with other languages (Erlang, LFE)
Elixir - Do we just follow the hype?
By Kevin Disneur
Elixir - Do we just follow the hype?
- 2,095