Say Hello to Elixir

Say Hello to Elixir

Presented at The Guild on Feb 27th, 2014, this is a look at Elixir, how it works, and what we can learn from its concepts and philosophy in our everyday object-oriented programming.

241eb3a089132c5a0c65e765558a6735?s=128

Arjan van der Gaag

February 27, 2014
Tweet

Transcript

  1. Arjan van der Gaag @avdgaag • arjanvandergaag.nl

  2. None
  3. – erlang.org Erlang is a programming language used to build

    massively scalable soft real-time systems with requirements on high availability. Erlang's runtime system has built-in support for concurrency, distribution and fault tolerance.
  4. Anonymous functions iex> Enum.map [1, 2, 3], fn n ->

    n * 2 end [2, 4, 6] iex> Enum.map [1, 2, 3], &(&1 * 2) [2, 4, 6]
  5. Named functions & modules defmodule Greeter do def greet(name) do

    IO.puts "Hello, #{name}" end end iex> Greeter.greet("James") "Hello, James" iex> Enum.each ["john", “paul”], &Greeter.greet/1 "Hello, john" "Hello, paul"
  6. defmodule MyMap do ! ! ! ! ! end Pattern

    matching ! def map([], _), do: [] ! ! ! def map([head | tail], fun) do [fun.(head) | map(tail, fun)] end
  7. Pipelines iex> String.last(String.upcase("foo")) "O" iex> "foo" ...> |> String.upcase ...>

    |> String.last "O"
  8. Assert defmodule TruthTest do use ExUnit.Case test "considers two strings

    equal" do assert "foo" == "bar" end end ! ! ! ! ! ! ! ! 1) test considers two strings equal (TruthTest) ** (ExUnit.ExpectationError) expected: "foo" to be equal to (==): "bar" at test/demo/truth_test.exs:5
  9. Macros for
 Metaprogramming
 Mayhem

  10. Actors fib = spawn(Fibonacci, :server, [self]) fib <- { :number,

    17 } ! ! ! receive do ! ! ! ! ! ! end ! ! ! ! { :ok, result } -> IO.puts "Received response:" IO.puts result ! ! ! ! ! ! ! { _, error } -> IO.puts “An error occured!” IO.puts error
  11. encapsulated
 state message message

  12. None
  13. Re-learn programming

  14. Practice makes perfect

  15. Pure functions and immutable data are easy to test.

  16. FP OOP

  17. ♥ docs

  18. Macros allow awesome metaprogramming

  19. Find out more • elixir-lang.org • erlang.org • Programming Elixir

    (Dave Thomas) • Meet Elixir (Peepcode play-by-play with José Valim) • exercism.io • Gary Bernhardt: Boundaries