Pro Yearly is on sale from $80 to $50! »

An Introduction to Elixir

An Introduction to Elixir

Covers the basics of the language, what it can be used for and why it's particularly helpful for certain situations. A great talk for people new to or curious about Elixir.

Links:

* Mike Zornek: For Hire | http://mikezornek.com/for-hire/
* Elixir Language Website Guide | https://elixir-lang.org/getting-started/introduction.html
* Elixir School | https://elixirschool.com/en/
* Elixir in Action (Book) | https://www.manning.com/books/elixir-in-action
* The Pragmatic Studio (Videos) | https://pragmaticstudio.com/elixir
* ElixirConf | https://www.youtube.com/channel/UC0l2QTnO1P2iph-86HHilMQ/videos

68d48587fc806c2b35eb9ff0b7ad8115?s=128

Mike Zornek

April 14, 2020
Tweet

Transcript

  1. An Introduction to Elixir April 2020 • Mike Zornek

  2. http://mikezornek.com

  3. Elixir is a dynamic, functional language designed for building scalable

    and maintainable applications. Elixir leverages the Erlang VM, often called the BEAM, which is known for running low-latency, distributed and fault-tolerant systems.
  4. Origins

  5. José Valim

  6. None
  7. None
  8. Elixir is a dynamic, functional language designed for building scalable

    and maintainable applications. Elixir leverages the Erlang VM, often called the BEAM, which is known for running low-latency, distributed and fault-tolerant systems.
  9. * Code Expectations

  10. Functional Language

  11. defmodule Greeter do def hello(name) do "Hello, " <> name

    end end iex> Greeter.hello("Sean") "Hello, Sean"
  12. # Other Languages baz(new_function(other_function()) # Elixir’s Pipe Operator other_function() |>

    new_function() |> baz()
  13. iex> String.split("Elixir rocks") ["Elixir", "rocks"] iex> "Elixir rocks" |> String.split()

    ["Elixir", "rocks"]
  14. iex> String.split("bread;milk;eggs", ";") ["bread", "milk", "eggs"] iex> "bread;milk;eggs" |> String.upcase()

    |> String.split(";") ["BREAD", "MILK", "EGGS"]
  15. Dynamic

  16. No Strict Typing

  17. defmodule Greeter do def hello(name) do "Hello, " <> name

    end end iex(3)> Greeter.hello(6) ** (ArgumentError) argument error :erlang.byte_size(6) iex:3: Greeter.hello/1 iex(3)> Greeter.hello(true) ** (ArgumentError) argument error :erlang.byte_size(true) iex:3: Greeter.hello/1
  18. defmodule Greeter do @spec hello(String.t()) :: String.t() def hello(name) do

    "Hello, " <> name end end # ** (CompileError) greeter.ex:8: undefined function hello/1 hello(6)
  19. None
  20. Pattern Matching

  21. # Algebra 10 = x * 2

  22. iex(5)> x = 1 1

  23. iex(5)> x = 1 1 iex(6)> 1 = x 1

  24. iex(5)> x = 1 1 iex(6)> 1 = x 1

    iex(7)> 2 = x ** (MatchError) no match of right hand side value: 1 iex(7)>
  25. iex(7)> 3 = y ** (CompileError) iex:7: undefined function y/0

  26. # Tuples iex> {:ok, value} = {:ok, "Successful!"} {:ok, "Successful!"}

    iex> value "Successful!" iex> {:ok, value} = {:error} ** (MatchError) no match of right hand side value: {:error}
  27. Pattern Matching

  28. Metaprogramming

  29. defmodule Friends.Person do use Ecto.Schema schema "people" do field :first_name,

    :string field :last_name, :string field :age, :integer end end
  30. Scalable

  31. Process

  32. Process Mailbox State

  33. Process A Mailbox State Process B Mailbox State Messages

  34. defmodule Example do def listen do receive do {:ok, "coffee"}

    -> IO.puts("Coffee time!") {:ok, "tea"} -> IO.puts("Tea, Earl Gray, Hot.") end listen() end end
  35. iex> pid = spawn(Example, :listen, []) #PID<0.108.0> iex> send(pid, {:ok,

    "coffee"}) Coffee time! {:ok, "coffee"} iex> send(pid, :ok) :ok
  36. CPU CPU CPU CPU BEAM OS Thread OS Thread OS

    Thread OS Thread Process Process Process scheduler Process Process Process Process Process Process Process Process Process scheduler scheduler scheduler OS process
  37. BEAM Server CPU CPU CPU CPU CPU CPU CPU CPU

  38. BEAM Server CPU CPU CPU CPU CPU CPU CPU CPU

    Server CPU CPU CPU CPU CPU CPU CPU CPU Server CPU CPU CPU CPU CPU CPU CPU CPU Server CPU CPU CPU CPU CPU CPU CPU CPU
  39. None
  40. Fault-Tolerant

  41. Process Supervisor

  42. Process Supervisor Process Process

  43. Supervisor Process Process Process Supervisor Process Process Process Supervisor Process

    Process Process Supervisor Supervisor
  44. Low-Latency

  45. None
  46. None
  47. Maintainable

  48. None
  49. $ iex -S mix iex(1)> :observer.start()

  50. None
  51. None
  52. None
  53. None
  54. Notable Projects • Building web applications using Phoenix. • Working

    with databases using Ecto. • Assemble data processing pipelines with Broadway. • Crafting GraphQL APIs using Absinthe. • Deploying embedded software using Nerves.
  55. • Elixir Language Website Guide 
 https://elixir-lang.org/getting-started/introduction.html • Elixir School


    https://elixirschool.com/en/ • Elixir in Action (Book)
 https://www.manning.com/books/elixir-in-action • The Pragmatic Studio (Videos)
 https://pragmaticstudio.com/elixir • ElixirConf
 https://www.youtube.com/channel/UC0l2QTnO1P2iph-86HHilMQ/videos
  56. Thanks! Available For Hire: http://mikezornek.com/for-hire/ Contact: @zorn on Micro.Blog +

    Twitter