A Drop of Elixir
A short introduction to Elixir
Paweł Duda (@paweldude)
http://slides.com/pawelduda/a-drop-of-elixir#
Erlang
- Made by Ericsson to improve telephony applications (1986)
- Runs on BEAM (Bogdan/Björn's Erlang Abstract Machine) VM
- Open-sourced in 1998
Who even uses it?
http://stackoverflow.com/questions/1636455/where-is-erlang-used-and-why
TL;DR
- Facebook: chat backend, 100m active users
- WhatsApp: up to 2m connected users per server
- Yahoo!: bookmarking service, 5m users and 150m bookmarked URLs
http://stackoverflow.com/questions/1636455/where-is-erlang-used-and-why
Let's talk about Elixir
- First released in 2012
- Superset of the battle-tested Erlang
- Compiled to bytecode for BEAM
- Functional
- Immutable data structures
- Declarative
- Dynamic
- Everything is an expression
- Processes share nothing by default - they exchange messages (actor model)
- It stands still faster than Ruby sprints (and eats way less resources)
- Judging by the syntax it is very Ruby-like but the truth is far from that. Code written in Elixir tends to be more verbose and uses many different concepts.
http://techbeacon.com/5-emerging-programming-languages-bright-future
Somewhat off-topic quiz time!
Imperative vs declarative code
Which way to double this array is imperative and which is declarative?
a)
b)
Which way to double this array is imperative and which is declarative?
a) imperative
b) declarative
Regardless of how I get to your house, what really matters is the car I drive. Am I going to drive
an imperative stick shift car
or
a declarative automatic car.
- Tyler McGinnis
https://medium.freecodecamp.com/imperative-vs-declarative-programming-283e96bf8aea
Now that we know what imperative and declarative really means, let's get back to Elixir :)
Syntax and things I like about the language
so far
Anonymous functions
Inspect stuff
Modules + pattern matching
=
Modules + pattern matching
Modules + pattern matching
Let's go back to our TestPatternMatching.two_plus_two/1 and add some documentation
We now have documentation in Markdown
Let's add a test file...
Time to write some actual tests?
Nope, we already wrote them :)
The Markdown documentation has actual, runnable tests!
A good way to solve problems with an outdated documentation :)
mindblown.gif
The pipe operator |>
The task:
- Generate a list of numbers from 1 to 100
- Multiply each of these numbers by 2
- Get the sum of all odd numbers after multiplying them
The capture operator makes this even sexier :)
Supervisor
Live demo
Where to start
http://elixir-lang.org/getting-started/introduction.html
A Drop of Elixir
By Paweł Duda
A Drop of Elixir
- 1,238