Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

My elixir helWo lorld

108 views

Published on

An introduction to Elixir, by someone who has fiddled around with it for a while

Published in: Engineering
  • Be the first to comment

My elixir helWo lorld

  1. 1. My Elixir HelWo lolrd Why Elixir is the next big thing in tech world
  2. 2. Claudio D’Alicandro AdEspresso By Hootsuite Twitter: @_cdali Github: claudio-dalicandro
  3. 3. 19.000.000.000$ If you're thinking about WhatsApp, you're right... But what is behind a 19,000,000,000 dollars idea?
  4. 4. A bit 'of numbers referring to WhatsApp 35 The engineers who worked for WhatsApp before acquisition 450.000.000 WhatsApp users before acquisition
  5. 5. Erlang and the BEAM ● Light-weight process ● No memory sharing ● Code hot-swap out of the box ● Actor modeling ● Battle tested virtual machine
  6. 6. My trouble with Erlang ● Prolog-inspired syntax ● Single assignment sometimes is just as problematic as destructive assignment ● Strings-as-lists sucks
  7. 7. What if I told you that you can have all the advantages, and no flaws?
  8. 8. Elixir
  9. 9. The Toolbox
  10. 10. mix Mix is a build tool that provides tasks for creating, compiling, and testing Elixir projects, managing its dependencies, and more.
  11. 11. Mix Create an Elixir project is simple: $ mix new helwo_lorld --module HW
  12. 12. exUnit Unit testing framework for Elixir.
  13. 13. ExUnit ● Simple macros help defining readable tests ● ExUnit.DocTest implements functionality similar to Python’s doctest. ● ExUnit.Callbacks defines both setup_all and setup callbacks, as well as the on_exit/2 facility ● You can define the test as asynchronous by adding “async: true” in the use statement
  14. 14. Credo A static code analysis tool for the Elixir language with a focus on teaching and code consistency.
  15. 15. Credo ● shows you refactoring opportunities in your code ● shows complex or duplicated code fragments ● warns you about common mistakes ● shows inconsistencies in your naming scheme ● helps you enforce a desired coding style
  16. 16. The Language
  17. 17. Data types
  18. 18. Elixir Basic types ● Integer ● Float ● Boolean ● Atom ● String ● List ● Tuple
  19. 19. Keyword lists A keyword list is a list of tuples
  20. 20. Maps A map can be “updated” A map can be destructured through pattern matching
  21. 21. Pattern Matching
  22. 22. What is the pattern matching? Actually, your “=” operator sucks.
  23. 23. Destructuring You can use the pattern matching to destructure the input of a function
  24. 24. Pattern matching usages
  25. 25. Guards Clauses also allow extra conditions to be specified via guards
  26. 26. Polymorphism Finally, it is important to specify that by using pattern matching you can implement polymorphism, indeed, you can set the same function multiple times, so as to cover different patterns with different behaviors
  27. 27. Parallel processing
  28. 28. Spawn a process In Elixir, all code runs inside processes. Processes are isolated from each other, run concurrent to one another and communicate via message passing. Processes are not only the basis for concurrency in Elixir, but they also provide the means for building distributed and fault-tolerant programs.
  29. 29. Link and Monitoring The majority of times we spawn processes in Elixir, we spawn them as linked processes. When two process are linked the failure in one process propagates to the other. Finally, we can set up a monitor so that the parent process will receive a notification every time a child exits
  30. 30. Why processes are so important? Obviously the processes are primarily a tool to perform parallel computations, but thanks to the BEAM and the infinite number of processes that can run on the inside, they have become something more…
  31. 31. Actor Modeling
  32. 32. OTP No, this not means one time password The Open Telecom Platform is a collection of Middleware, libraries and tools
  33. 33. Tasks, Agents, GenServers, GenEvents... Tasks meant to execute one particular action throughout their lifetime, often with little or no communication with other processes. store state that must be accessed from different processes Agents standard set of interface functions,include functionalities for tracing and error reporting GenServers event manager process with an arbitrary number of event handlers which are added and deleted dynamically GenEvents
  34. 34. Actor Modeling
  35. 35. Questions?

×