Why Elixir

👍 or 👎

Problems to solve

NoMethodError (undefined method for nil)
  • Flexible
  • DSL friendly
  • Developer friendly
  • Flexible
  • DSL friendly
  • Developer friendly
input
|> (&(&1 + 1)).()
from p in Post,
  left_join: c in Comment,
  select: %{p | comments_count: count(c.id)},
  group_by: p.id
  order: [desc: p.published_at]
(1..1_000).reduce({}) do |acc, x|
  acc.merge(x => 1)
end

(1..1_000).reduce({}) do |acc, x|
  acc[x] = 1
  acc
end

Functional Programming

Too much Rails in Ruby

Architecture the Lost Years by Robert Martin - 2011

Japanese guys

Evolution, not revolution

  • multiple function signatures
  • cleaner flow
  • explicit intentions
  • faster validation
def foo(arg) do
  {:ok, val} = bar.call(baz, arg)
  ...
end

Structs

defmodule MyApp.Foo do
  @enforce_keys [:bar]
  defstruct [:foo, :bar]
  
  @spec call(%__MODULE__, number) :: %__MODULE__
  def call(%__MODULE__, val) do
    ...
  end
end
  

%MyApp.Foo{bar: bar} = baz()

Docs gratification

Elixir ❤️ DDD

  • Aggregates and Sagas as Processes
  • Commands and Events as messages
  • Commanded > RES

OTP

It's probably not too important, in the grand scheme of things, whether you are using a language like Erlang or not. While I do feel it's under-used and under-rated, the biggest benefit of it is not in running a system that uses it. The biggest benefit comes from learning about the fundamentals of solid system design and internalizing its lessons in a practical context.

Protocols and Behaviours

class FooAbstract
  def foo
    raise "Not Implemented Yet"
  end
end
defmodule Foo do
  @callback foo(String.t) :: {:ok, term}
end

defmodule Bar do
  @behaviour Foo
  
  @impl Foo
  def foo(str) do
    {:ok, :foo}
  end
end

Protocols and Behaviours

module Countable
  def size
    if respond_to?(:count)
      count
    else
      amount
    end
  end
end
defprotocol Countable do
  def count(input)
end

defimpl Countable, for: Foo do
  def count(foo), do: Foo.size(foo)
end

defimpl Countable, for: Bar do
  def count(bar), do: Bar.amount(bar)
end

Are we going to meet in the Elixir world?

  • A lot of success stories from product teams
  • Software houses struggle to sold Elixir
  • Lack of revolution effect

Why Elixir

By Jan Dudulski

Why Elixir

  • 110