- Rails is Immensely Popular
- Developer productivity is through the roof
- But has concurrency issues
- José Valim to make it threadsafe
BACK IN THE DAY
Slide 5
Slide 5 text
- Can never fully guarantee it
- Looked towards Functional Languages
- Erlang!
THREADSAFE RAILS
Slide 6
Slide 6 text
- Fast and Powerful
- Immutable
- Fault-tolerant
- Concurrent and Distributed
ERLANG-LOVE
Slide 7
Slide 7 text
JOSÉ VALIM
I liked everything I saw in Erlang,
but hated the things I didn’t see
“
Slide 8
Slide 8 text
- Awful Syntax
- Lack of Metaprogramming
- No Polymorphism
- No proper build tools
ERLANG-HATE
Slide 9
Slide 9 text
Decided to build his own language on the
ERLANG VM
Slide 10
Slide 10 text
ELIXIR IS BORN
Slide 11
Slide 11 text
ELIXIR-LANG.COM
A dynamic, functional language designed
for building scalable and maintainable
applications
“
some_data = [:fire, {32, 45, 73}, %{name: "Foo", desc: "Bar"}]
iex> [:water, {a, b, _}, %{name: name}] = some_data
** (MatchError) no match of right hand side value
PATTERN MATCHING
Slide 25
Slide 25 text
result = Directory.read_filenames()
case result do
{:ok, files} -> Enum.map(files, &IO.puts/1)
{:error, message} -> IO.puts "Can't read files: #{message}"
end
PATTERN MATCHING
Slide 26
Slide 26 text
defmodule Area do
def rectangle(l, w) do
l * w
end
end
iex> Area.rectangle(2, 3)
6
MODULES
Slide 27
Slide 27 text
defmodule Area do
def rectangle(l, w), do: l * w
def square(l), do: rectangle(l, l)
def circle(r), do: 3.14 * square(r)
end
Area.square(4) # => 16
Area.circle(5) # => 78.5
MODULES
Slide 28
Slide 28 text
iex> circle_radii = [1, 2, 3]
iex> Enum.map circle_radii, fn r -> Area.circle(r) end
[3.14, 12.56, 28.26]
CAPTURE OPERATOR
defmodule Rectangle do
defstruct [:length, :width]
def area(rect), do: rect.length * rect.width
end
iex> rect = %Rectangle{length: 10, width: 5}
iex> Rectangle.area(rect)
50
STRUCTS
Slide 31
Slide 31 text
# Double, reverse and then print items in a list
my_list = [1, 2, 3, 4, 5]
doubled_list = Enum.map(my_list, fn x -> x * 2 end)
reverse_list = Enum.reverse(doubled_list)
Enum.map(reverse_list, &IO.puts/1)
PIPE OPERATOR
Slide 32
Slide 32 text
# Double, reverse and then print items in a list
Enum.map(
Enum.reverse(
Enum.map([1, 2, 3, 4, 5], fn x -> x * 2 end)
),
&IO.puts/1
)
PIPE OPERATOR
Slide 33
Slide 33 text
# Double, reverse and then print items in a list
[1, 2, 3, 4, 5]
|> Enum.map(fn x -> x*2 end)
|> Enum.reverse
|> Enum.map(&IO.puts/1)
PIPE OPERATOR
Slide 34
Slide 34 text
defprotocol JSON do
def encode(item)
end
POLYMORPHISM
defimpl JSON, for: String do
def encode(s), do: "\"#{s}\""
end
defimpl JSON, for: CustomModule do
def encode(item) do
# do something
end
end
Slide 35
Slide 35 text
METAPROGRAMMING
- via Macros
- Elixir is written in Elixir!
- Almost everything is a Macro
def, defmodule, if-else, and, or, !, |>, and so much more
Slide 36
Slide 36 text
defmacro macro_unless(clause, expression) do
quote do
if(!unquote(clause), do: unquote(expression))
end
end
METAPROGRAMMING
Slide 37
Slide 37 text
$ mix new my_app
$ mix deps.get
$ mix test
$ mix run
$ iex -S mix
MIX
Slide 38
Slide 38 text
THE FUTURE
Slide 39
Slide 39 text
- Growing at an amazing rate
- Backed by major players from Rails, Erlang & Node.js
communities
- Erlang libraries at disposal
COMMUNITY
Slide 40
Slide 40 text
- Elixir’s Rails
- Super-fast and developer-friendly
- Requests completed in microseconds (µs)
- Tons of guides and resources already available
PHOENIX FRAMEWORK
Slide 41
Slide 41 text
- PHP with Open Source
- Rails with Developer Productivity
- Elixir with Performance
(without sacrificing developer happiness)
THE NEXT REVOLUTION