Drupaler drinks some Elixir
What happens next?

Janez Urevc | @slashrsm | janezurevc.name

static.janezurevc.name/elixir_ddd2017

Photo by: Dasjo

Janez Urevc (@slashrsm)

  • senior engineer at MD Systems
  • in Drupal community since 2009
  • D8 media initiative lead
  • ex Examiner.com
  • media all the way :)

- top contributors

  • our CTO (@berdir) is one of top 5 D8 contributors
  • D8 expert
  • D8 media expert - lots of media clients
  • 20% of every project to the community
  • Full projects, audits, bootstrap weeks, consulting, architecture, ...

Elixir?

  • functional programming language
  • modern (since 2011)
  • highly concurrent
  • fast
  • compiled
  • built on Erlang
  • Used by Pinterest, The book of everyone, Bleacher report, Brightcove, ...

Erlang?

  • general-purpose functional language
  • built in 1986 at Ericsson
  • initially for telephone switches
  • distributed
  • fault-tolerant
  • highly-available
  • soft real-time
  • code hot swapping
  • Open Telecom Platform (OTP)
-

Why functional?

  • only pure functions
  • no state
  • clean and easy to understand code
  • maintainability
  • concurrency! (multi-core anyone?)

Cool stuff: sub-process


current_process = self()

# Spawn an Elixir process (not an operating system one!)
spawn_link(fn ->
  send current_process, {:msg, "hello world"}
end)

# Block until the message is received
receive do
  {:msg, contents} -> IO.puts contents
end
      

Cool stuff: pattern matching


iex> {a, b, c} = {:hello, "world", 42}
{:hello, "world", 42}

iex> a
:hello

iex> b
"world"
      

Cool stuff: pattern matching


def handle_result(res) do
  case res do
    {:ok, customer} ->
      "A customer was created with ID #{customer.id}"
    {:error, reason} ->
      "Customer could not be created because #{reason}"
    _ ->
      "An unknown error occurred. #{other}"
  end
end
      

Cool stuff: pattern matching


def handle_result(res) do
  case res do
    {:ok, customer} ->
      "A customer was created with ID #{customer.id}"
    {:error, reason} ->
      "Customer could not be created because #{reason}"
    _ ->
      "An unknown error occurred. #{other}"
  end
end
      

Cool stuff: binary pattern matching


def parse_binary(<<head :: binary-4, body :: binary>>) do
  # do stuff
end
      
zohaib.me/binary-pattern-matching-in-elixir/

Cool stuff: observer

  • built-in monitoring tool
  • you can run it on prod
  • a lot of real-time info about the app

More cool stuff

  • ETS (replacement for Redis)
  • DETS (replacement for Redis)
  • Mnesia (built in RDMS)
  • distributed execution (scalability)
  • ...

Phoenix

  • web framework
  • inspired by Ruby on Rails
  • OTP app
  • gets all benefits of Elixir/Erlang
  • we tried it on an internal project

  • embedded software platform
  • builds and deploys any Elixir app
  • app as little as 12MB
  • Raspberry PI, Beaglebone black
  • ... yes, you can run Phoenix on it
  • IoT anyone?

Lessons learned

  • very different than PHP
  • must get used to functional approach
  • young language
  • PHP is *super* rich
  • strtotime() is a blessing! :)

What is the point?

Thank you! Questions?

Janez Urevc | @slashrsm | janezurevc.name

static.janezurevc.name/elixir_ddd2017