Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Elixir Mini Introduction for Zürich Meetup

Elixir Mini Introduction for Zürich Meetup

Stefan Wintermeyer

February 20, 2017
Tweet

More Decks by Stefan Wintermeyer

Other Decks in Technology

Transcript

  1. Elixir
    Stefan Wintermeyer
    @wintermeyer

    View Slide

  2. Elixir is a functional, concurrent,
    general-purpose programming
    language that runs on the Erlang
    virtual machine (BEAM).
    https://en.wikipedia.org/wiki/Elixir_(programming_language)

    View Slide

  3. defmodule ModuleName do
    def hello do
    IO.puts "Hello World"
    end
    end
    http://elixir-lang.org/crash-course.html

    View Slide

  4. IEx
    Elixir’s interactive shell

    View Slide

  5. View Slide

  6. Why would I want to
    learn Elixir?
    Why invest the time and effort? I’m happy with Ruby and OO.

    View Slide

  7. Three Main Reasons
    Spoiler Alert: Concurrency is not one of them.

    View Slide

  8. 1. Speed
    Elixir runs circles around Ruby and Python.

    View Slide

  9. 2. Stability
    Speed is nothing without stability.

    View Slide

  10. 3. Hot-Code Upgrades
    Zero Downtime!

    View Slide

  11. Some Code Examples

    View Slide

  12. Assigning Values to
    Variables

    View Slide

  13. iex(1)> a = 1
    1
    iex(2)>

    View Slide

  14. iex(1)> a = 1
    1
    iex(2)> a = 2
    2
    iex(3)>

    View Slide

  15. iex(1)> a = 1
    1
    iex(2)> a = 2
    2
    iex(3)> ^a = 3
    ** (MatchError) no match of right hand
    side value: 3

    View Slide

  16. Tuples

    View Slide

  17. iex(1)> {a, b, c} = {10, 20, 30}
    {10, 20, 30}
    iex(2)>

    View Slide

  18. iex(1)> {a, b, c} = {10, 20, 30}
    {10, 20, 30}
    iex(2)> a
    10
    iex(3)>

    View Slide

  19. Pattern Matching

    View Slide

  20. iex(1)> {a, b, c} = {10, 20, 30}
    {10, 20, 30}
    iex(2)>

    View Slide

  21. iex(1)> {a, b, c} = {10, 20, 30}
    {10, 20, 30}
    iex(2)> {a, 20, c} = {10, 20, 30}
    {10, 20, 30}
    iex(3)>

    View Slide

  22. iex(1)> {a, b, c} = {10, 20, 30}
    {10, 20, 30}
    iex(2)> {a, 20, c} = {10, 20, 30}
    {10, 20, 30}
    iex(3)> {a, 1, c} = {10, 20, 30}
    ** (MatchError) no match of right hand
    side value: {10, 20, 30}

    View Slide

  23. If you want to get your
    feed wet with Elixir I
    recommend two projects.

    View Slide

  24. If you like hardware try
    http://nerves-project.org

    View Slide

  25. View Slide

  26. If you like the web try
    www.phoenixframework.org

    View Slide

  27. View Slide

  28. Phoenix Framework
    Productive. Reliable. Fast.
    Phoenix != Rails

    View Slide

  29. View Slide

  30. mix phoenix.new blog
    Y
    cd blog
    vim config/dev.exs
    brew install postgres
    brew services start postgres
    createuser -W --createdb blog
    demo
    mix ecto.create
    mix phoenix.gen.html Post posts subject body
    vim web/router.ex
    resources "/posts", PostController
    mix ecto.migrate
    mix phoenix.server
    Blog Example

    View Slide

  31. Thank you!
    @wintermeyer

    View Slide