$30 off During Our Annual Pro Sale. View Details »

Let's talk about Elixir

Let's talk about Elixir

Introductory talk about Elixir, showcasing the core features and aims of the language.

Dimitrios Zorbas

May 11, 2016
Tweet

More Decks by Dimitrios Zorbas

Other Decks in Programming

Transcript

  1. Let’s Talk About
    Dimitris Zorbas - Athens Ruby Meetup#26
    github.com/zorbash @_zorbash

    View Slide

  2. is a functional, concurrent language designed for
    building scalable and maintainable applications.
    Dimitris Zorbas - Athens Ruby Meetup#26
    The power of Erlang meets the joy of Ruby!

    View Slide

  3. Why Bother?
    ➔ Created by a rubyist
    aimed to rubyists
    ➔ Learn a new language
    every year
    ➔ Even Matz likes it!
    Dimitris Zorbas - Athens Ruby Meetup#26

    View Slide

  4. Really Why Bother?
    Seems to solve the core issues of Ruby
    (performance / scalability / maintainability),
    adopting a functional programming model, with a
    sweet Ruby-like syntax and cherries on top.
    Dimitris Zorbas - Athens Ruby Meetup#26

    View Slide

  5. Really Why Bother?
    Dimitris Zorbas - Athens Ruby Meetup#26

    View Slide

  6. Features
    Immutability
    Dimitris Zorbas - Athens Ruby Meetup#26
    will_change = 42
    answer = fn -> will_change end
    will_change = 1337
    answer.()
    # => 42

    View Slide

  7. Features
    Pipelines
    Dimitris Zorbas - Athens Ruby Meetup#26
    [42, nil, 1337, nil, 4]
    |> Enum.filter(&(&1))
    |> Enum.map(&(&1 * 2))
    |> Enum.sort
    |> Enum.join(", ")
    # => "84, 2674, 8"

    View Slide

  8. Features
    Pattern-Matching
    Dimitris Zorbas - Athens Ruby Meetup#26
    Pattern matching is one of the cornerstones of an equational style of
    definition; more often than not it leads to a cleaner and more readily
    understandable definition than a style based on conditional
    equations. It also simplifies the process of reasoning formally about
    functions.

    View Slide

  9. Features
    Pattern-Matching
    Dimitris Zorbas - Athens Ruby Meetup#26
    defmodule Speaker do
    def talk(:bob), do: "Hi, uncle Bob!"
    def talk(42), do: "Oh! the answer to life the universe and everything"
    def talk(n) when is_number(n), do: "You're an ordinary number"
    def talk(_), do: "I don't really know what to tell you"
    end

    View Slide

  10. Concurrency: Actor Model
    Features
    Dimitris Zorbas - Athens Ruby Meetup#26
    Processes (actors) are the center of computation and have mailboxes.
    They communicate by sending asynchronous messages to each other.

    View Slide

  11. Concurrency: Actor Model
    Features
    Dimitris Zorbas - Athens Ruby Meetup#26
    OOP to me means only messaging, local retention and protection and
    hiding of state-process and extreme late-binding of all things.

    View Slide

  12. Dimitris Zorbas - Athens Ruby Meetup#26
    defmodule Speaker do
    import IO, only: [puts: 1]
    def new, do: spawn &start/0
    def start do
    receive do
    {:answer, name} -> puts talk(name)
    _ -> puts "I don't know how to handle that"
    after
    2000 -> puts "[#{inspect(self)}] Tell me something to do"
    end
    start
    end
    def talk(:bob), do: "Hi, uncle Bob!"
    def talk(42), do: "Oh! the answer to life the universe and everything"
    def talk(n) when is_number(n), do: "You're an ordinary number"
    def talk(_), do: "I don't really know what to tell you"
    end

    View Slide

  13. Features
    Async Tests
    defmodule SpeakerTest do
    use ExUnit.Case, async: true # Examples run concurrently
    test "talking to bob" do
    assert Speaker.talk(:bob) == "Hi, uncle Bob!"
    End
    test "talking to a stranger" do
    assert Speaker.talk(:voldemort) == "I don't really know what to tell you"
    end
    end
    Dimitris Zorbas - Athens Ruby Meetup#26

    View Slide

  14. Erlang Interoperability
    Features
    Dimitris Zorbas - Athens Ruby Meetup#26
    Erlang / LFE (Lisp-Flavored-Erlang) / Elixir all run on BEAM
    OTP is directly available in Elixir

    View Slide

  15. Live Fast, Die Young
    Philosophy
    Dimitris Zorbas - Athens Ruby Meetup#26

    View Slide

  16. Live Fast, Die Young
    Philosophy
    Dimitris Zorbas - Athens Ruby Meetup#26
    ● Failures are embraced and managed. Let it crash!
    ● Failure is isolated in process level. No exceptions.
    ● Failing fast is revealing. The system stays up.
    ● Write Offensive Code

    View Slide

  17. Live Fast, Die Young
    Philosophy
    Dimitris Zorbas - Athens Ruby Meetup#26
    The world is concurrent. Things in the world don't share data.
    Things communicate with messages. Things fail.

    View Slide

  18. Resources
    Dimitris Zorbas - Athens Ruby Meetup#26
    ● http://elixir-lang.org/getting-started/introduction.html
    ● http://elixirplayground.com/
    ● https://elixir-lang.slack.com/

    View Slide

  19. you |> ask :questions |> Enum.any?

    View Slide