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.
Learning Elixir
What is it good for?
■ Fault tolerance - maximum uptime
■ Large number of connections / IO
■ High level of concurrency
■ D...
1.
Built on Erlang
Erlang - 1986
It was originally designed by Ericsson to support
distributed, fault-tolerant, soft real-time, highly
availa...
WhatsApp
Messaging app
acquired by Facebook
for $19 billion. Used
Erlang for handling 2
million connections a
server. 10 t...
Erlang downsides?
■ Learning Curve
■ Syntax based on Prolog, not as
approachable (to some)
2.
Enter Elixir
About Elixir
■ Invented by José Valim, Rails committer
■ Syntax inspired by
○ Ruby
○ Clojure
■ Nicely bring together stren...
Look familiar?
Beyond Ruby...
Pattern Matching
[h | _] = [1, 2, 3]
Immutability
socket
|> read_line()
|> write_line(socket)
Pipe Operator...
Immutability
Immutable data structures
Potential source of errors in Ruby:
Immutable data structures
What’s wrong with this?
■ You don’t know what to expect of your
data when you call a method
■ Es...
Immutable data structures
In Elixir all data structures are immutable!!
■ You can safely share with other
processes
■ Don’...
Immutable data structures
Pattern Matching
Pattern Matching
‘=’ operator in action:
“
You Keep Using That Word, I Do Not Think It
Means What You Think It Means
Pattern Matching
The ‘=’ operator handles assignment and
comparison at the same time.
Can “destructure” complex types and
...
Pattern matching
Fail when error code is not as expected:
Pluck out variables from complex
structures
Pattern matching in methods
Multiple method definitions, match params:
No need for guards inside methods
Pipe Operator
Pipe Operator
■ Functional Programming: Series of data
transformations.
■ Pipe operator makes this cleaner:
|>
Pipe Operator
Metaprogramming
Metaprogramming
VS.
Macros
■ Allow extension of the language in a
clean way
■ Can control execution of passed in code
■ Gives you access to pa...
Processes
Lightweight processes / Message passing
■ Native support for lightweight processes
■ Can start tens of thousands of proces...
Lightweight processes / Message passing
OTP
OTP / Supervision hierarchy
■ OTP= “Rails” of event driven architecture
■ Supervision hierarchies help you define
fault to...
Fault tolerance / supervision
Distribution
■ Distribution is free!
■ Can send and receive messages from
other nodes
■ Can supervise other nodes
Tooling
Growing Ecosystem
Number of tools is growing
Rails Phoenix
ActiveRecord Ecto
Rack Plug
irb iex
rake / bundler mix
Benchmarks
Phoenix
Working on Exq library - Sidekiq for Elixir
Feel free to help out!
Try it out!
Resources
■ http://elixir-lang.org/crash-course.html
■ http://learnyousomeerlang.com/
■ https://pragprog.com/book/elixir/p...
You’ve finished this document.
Download and read it offline.
Upcoming SlideShare
Gp carlos pellegrini
Next
Upcoming SlideShare
Gp carlos pellegrini
Next
Download to read offline and view in fullscreen.

Share

Learning Elixir as a Rubyist

Download to read offline

Elements of Elixir compared to Ruby

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all

Learning Elixir as a Rubyist

  1. 1. Learning Elixir
  2. 2. What is it good for? ■ Fault tolerance - maximum uptime ■ Large number of connections / IO ■ High level of concurrency ■ Distributed across machines
  3. 3. 1. Built on Erlang
  4. 4. Erlang - 1986 It was originally designed by Ericsson to support distributed, fault-tolerant, soft real-time, highly available, non-stop applications. It supports hot swapping, thus code can be changed without stopping a system.
  5. 5. WhatsApp Messaging app acquired by Facebook for $19 billion. Used Erlang for handling 2 million connections a server. 10 team members work on Erlang and they handle both development and ops. RabbitMQ RabbitMQ is an open source message broker software that implements the Advanced Message Queuing Protocol (AMQP). It is fault tolerant and distributed. Riak is a distributed NoSQL key-value data store that offers high availability, fault tolerance, operational simplicity, and scalability. Erlang in the Wild
  6. 6. Erlang downsides? ■ Learning Curve ■ Syntax based on Prolog, not as approachable (to some)
  7. 7. 2. Enter Elixir
  8. 8. About Elixir ■ Invented by José Valim, Rails committer ■ Syntax inspired by ○ Ruby ○ Clojure ■ Nicely bring together strengths of these languages while gaining benefits of Erlang VM
  9. 9. Look familiar?
  10. 10. Beyond Ruby... Pattern Matching [h | _] = [1, 2, 3] Immutability socket |> read_line() |> write_line(socket) Pipe Operator socket |> read_line() |> write_line(socket) Protocols defprotocol Blank do @doc "Returns true if empty" def blank?(data) end LW Processes send self(), {:hello, "world"} receive do {:hello, msg} -> msg {:world, msg} -> "won't match" end Metaprogramming quote do: sum(1, 2 + 3, 4)
  11. 11. Immutability
  12. 12. Immutable data structures Potential source of errors in Ruby:
  13. 13. Immutable data structures What’s wrong with this? ■ You don’t know what to expect of your data when you call a method ■ Especially painful for threading ○ Concurrent modification errors ○ Race conditions
  14. 14. Immutable data structures In Elixir all data structures are immutable!! ■ You can safely share with other processes ■ Don’t have to worry about data changing under the covers
  15. 15. Immutable data structures
  16. 16. Pattern Matching
  17. 17. Pattern Matching ‘=’ operator in action:
  18. 18. “ You Keep Using That Word, I Do Not Think It Means What You Think It Means
  19. 19. Pattern Matching The ‘=’ operator handles assignment and comparison at the same time. Can “destructure” complex types and assign variables automatically.
  20. 20. Pattern matching Fail when error code is not as expected: Pluck out variables from complex structures
  21. 21. Pattern matching in methods Multiple method definitions, match params: No need for guards inside methods
  22. 22. Pipe Operator
  23. 23. Pipe Operator ■ Functional Programming: Series of data transformations. ■ Pipe operator makes this cleaner: |>
  24. 24. Pipe Operator
  25. 25. Metaprogramming
  26. 26. Metaprogramming VS.
  27. 27. Macros ■ Allow extension of the language in a clean way ■ Can control execution of passed in code ■ Gives you access to passed in AST
  28. 28. Processes
  29. 29. Lightweight processes / Message passing ■ Native support for lightweight processes ■ Can start tens of thousands of processes ■ Processes are isolated ■ Communicate via messages
  30. 30. Lightweight processes / Message passing
  31. 31. OTP
  32. 32. OTP / Supervision hierarchy ■ OTP= “Rails” of event driven architecture ■ Supervision hierarchies help you define fault tolerance ■ “Let it crash” - reboot with known state ■ Define supervisors for processes and the process / dependencies for restarting
  33. 33. Fault tolerance / supervision
  34. 34. Distribution ■ Distribution is free! ■ Can send and receive messages from other nodes ■ Can supervise other nodes
  35. 35. Tooling
  36. 36. Growing Ecosystem Number of tools is growing Rails Phoenix ActiveRecord Ecto Rack Plug irb iex rake / bundler mix
  37. 37. Benchmarks
  38. 38. Phoenix
  39. 39. Working on Exq library - Sidekiq for Elixir Feel free to help out!
  40. 40. Try it out!
  41. 41. Resources ■ http://elixir-lang.org/crash-course.html ■ http://learnyousomeerlang.com/ ■ https://pragprog.com/book/elixir/programming-elixir ■ https://www.manning.com/books/elixir-in-action ■ http://www.infoq.com/presentations/Value-Identity-State-Rich-Hickey ■ https://github.com/mroth/phoenix-showdown
  • abahkaiyisah

    Dec. 31, 2016
  • anheibiji

    Nov. 14, 2016
  • satosuyama

    Dec. 20, 2015

Elements of Elixir compared to Ruby

Views

Total views

1,386

On Slideshare

0

From embeds

0

Number of embeds

25

Actions

Downloads

9

Shares

0

Comments

0

Likes

3

×