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

Elixir: Why Processes Trump Objects

Elixir: Why Processes Trump Objects

Over the past quarter-century, we’ve witnessed the rise and widespread adoption of object-oriented (OO) languages. We bought into the promise that objects would solve all our technical challenges. That class hierarchies would bring order to our tangled messes. But something has gone horribly wrong.

The technical requirements of our software continue to rise, and our trusty OO languages aren’t keeping up. They’re unable to climb the ladder of complexity. How do we scale the complexity of a system without being crushed by the cognitive overhead it takes to keep it all in our head?

Kevin Rockwood explores how process-oriented architecture embodies the principles that object-oriented architecture always intended and explains how you can use processes to tackle complex problems that other languages could only dream about. For the past 30 years, Erlang, along with its pioneering runtime, has been quietly fighting alongside its OO brethren. Although its approach is drastically different from the OO languages of today, it’s actually much more closely aligned to object-oriented guiding principles. Now, Elixir is catapulting the pioneering approach of Erlang into the mainstream. The wave is approaching. Choose processes over objects, and embrace the magic of Elixir.

Kevin Rockwood

May 19, 2016
Tweet

More Decks by Kevin Rockwood

Other Decks in Technology

Transcript

  1. ALAN KAY “I thought of objects being like biological cells

    and/or individual computers on a network, only able to communicate with messages”
  2. • Implements the actor model with Erlang processes • Libraries

    for managing the process lifecycle • Hot code swapping • Data persistance OTP Framework
  3. Processes Have State defmodule MyProcess do def init() do {:ok,

    []} end def handle_call({:push, message}, state) do {:ok, [message | state]} end end > {:ok, pid} = MyProcess.start_link // state = [] > MyProcess.push(pid, "Hello World") // state = ["Hello World"]
  4. // Phoenix Channel def handle_in("crawl", %{"url" => url}, socket) do

    Crawler.start(url) receive do {:page, new_page} -> push(socket, "new_page", new_page) {:link, new_link} -> push(socket, "new_link", new_link) end end
  5. %{ root: "example.com", pages: %{ "example.com" => %{id: 1} "example.com/page_1"

    => %{id: 2} "example.com/page_3" => %{id: 3} }, links: [ %{target: 1, source: 2}, %{target: 2, source: 1}, %{target: 2, source: 3}, %{target: 3, source: 1}, ] } Crawler Connection Pool
  6. • Objects should be completely isolated • Objects should only

    communicate via message passing • Objects should be fault tolerant What is Object Oriented?
  7. • Processes should be completely isolated • Processes should only

    communicate via messaging • Processes should be fault tolerant What is Object Oriented?