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

Let's create stateful systems, by Elixir

Let's create stateful systems, by Elixir

4b071f90c5d9c0a58e2d9076460b7be4?s=128

さっちゃん

August 24, 2019
Tweet

Transcript

  1. Let's create stateful systems, by Elixir

  2. . 。oO( さっちゃんですよヾ( 〃l _ l) ノ゙☆)

  3. I'll show you a number.

  4. 2

  5. Two

  6. 2 is a number of collison & collaboration.

  7. I & you hot & ice stand up & lie

    down inside & outside
  8. stateless & stateful

  9. Function is stateless. f : x -> y e.g. Web

    server
  10. Dialogue is stateful. Alice : X. Bob : Y. Alice

    : X. Bob : Z. Most of the system is stateful.
  11. Elixir

  12. Elixir is a functional programming language. Functional programming is stateless.

    All data of Elixir is immutable. [x, 3, x] = Enum.map([1,2,1], &(&1 + 1)) assert 2 == x // Many lines that don't reassign to `x`. assert 2 == x
  13. Elixir has processes. 29 = Task.async(fn -> 29 end) |>

    Task.await
  14. Process has state. agent = Agent.start_link(fn -> 29 end) 29

    = Agent.get(agent, &(&1)) Agent.update(agent, &(&1 + 13)) 42 = Agent.get(agent, &(&1))
  15. State should be updated in a transaction. State shold interact

    & isolate each other. Accessing to state should be scaled in-out. Server with state should be updated gracefully. Elixir has all of these!
  16. State should be updated in a transaction. (No shared state)

    State shold interact & isolate each other. (Application, Supervisor) Accessing to state should be scaled in-out. (GenStage, Task, Register, Erlang cluster) Server with state should be updated gracefully. (Hot code swap)
  17. We can create stateful system easy, by constructing stateless parts.

  18. How we can start Elixir? Let's create some applications. *

    Web application with Phoenix. * Slack bot.
  19. Phoenix is a Web application framework that familiar with WebSocket.

    https://hexdocs.pm/phoenix/overview.html
  20. React is available (✿ >ヮ ╹ )-♡ Let's create a

    realtime interaction ∩ (> ◡ <*)∩ ♡ https://speakerdeck.com/ne_sachirou/phoenix-livereact
  21. Create a Slack bot. https://github.com/BlakeWilliams/Elixir-Slack (Easy, so no topic.)

  22. Installing Elixir. asdf https://asdf-vm.com/ asdf plugin-add erlang asdf install erlang

    22.0.7 asdf plugin-add elixir asdf install elixir 1.9.1
  23. Text editor? VSCode with mjmcloug.vscode-elixir works.

  24. Format & lint. InnerCotton https://github.com/ne-sachirou/inner_cotton is a set of standard

    development tools. mix cotton.init mix cotton.lint --fix
  25. Docker image (You need Docker :-) Fix major ver.s both

    Erlang & Elixir. docker run -it --rm nesachirou/elixir:1.9_erl22
  26. Textbook & document. Official guide : https://elixir-lang.org/ Official document :

    https://hexdocs.pm/elixir/Kernel.html Online textbook : https://elixirschool.com/ja/ Textbook : https://tatsu-zine.com/books/programming-elixir-ja
  27. https://speakerdeck.com/ne_sachirou/elixirwan-quan-nili-jie-sita

  28. Advanced resources

  29. Erlang in Anger https://ymotongpoo.github.io/erlang-in-anger/text-ja.pdf You want to read this… before

    production.
  30. https://speakerdeck.com/ne_sachirou/sutetohurudeda-gui-mo- akusesufalsearusoft-realtimenagemusabawoeasynitukuru

  31. https://speakerdeck.com/ne_sachirou/elixir-on-containers

  32. https://speakerdeck.com/ne_sachirou/phoenix-at-scale

  33. https://speakerdeck.com/ne_sachirou/ddd-data-driven-development