drinking the elixir - yow! conferences · elixir is what would happen if erlang, clojure, and ruby...

37
Drinking the Elixir @jocranford

Upload: others

Post on 10-Aug-2020

3 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Drinking the Elixir@jocranford

Page 2: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature
Page 3: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Why Elixir?

Concurrency Support

Accessibility

Performance

Impact on hiring

Page 4: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

🤔 But why not just write Erlang?

Page 5: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Elixir =

Erlang libraries + Elixir tools

Elixir

Erlang

Page 6: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Prolog sucks ass for building entire applications. But that hasn't deterred Erlang from stealing it's

dynamite syntax.

Damien Katz, creator of Couch DB

Page 7: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Despite some great properties, I never was (and I’m still not) quite comfortable programming in Erlang. The coding experience somehow never felt very fluent, and the

resulting code was always burdened with excessive boilerplate and duplication.

Saša Jurić, author of Elixir in Action

Page 8: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

!= +

Page 9: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Our Journey.

Page 10: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Doing concurrency in Erlang or Elixir versus other languages is a bit like doing branches in Git vs Subversion.

Devin Torres, Nano Core Team

Page 11: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

OTP

Page 12: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

OhteepeeOTP

Page 13: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Ohteepee

Concurrent Systems Platform

OTP

Page 14: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Supervisor

Supervisor

Worker Worker Worker

Worker WorkerWorker

Page 15: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Monolith Ruby on Rails

Unicorn

Worker Worker

Worker Worker

Page 16: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

A little story about workers dying quietly.

Page 17: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

What we learned

sasl logging library is excellent

Workers that die gracefully are not restarted

Page 18: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

What we learned

sasl logging library is excellent

Workers that die gracefully are not restarted

Expect the unexpected

Be prepared for some frustration

Page 19: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Accessibility

class Greeter def hello(name) puts "Hello, #{name}" end end

Greeter.new.hello("Jo")

defmodule Greeter do def hello(name) do IO.puts "Hello, #{name}" end end

Greeter.hello("Jo")

Page 20: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Elixir looks familiar

Map Hash

List Array

sort of like

sort of like

Atom Symbolequivalent of

Enum similar interface to Enum

Stream similar interface to Stream

Page 21: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

The Paradigm Shift

When we fell in love with Elixir

Page 22: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

The Pipe Operator

|>

Page 23: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

def index(conn, _params) do status = MicroStatus.version(Waffle.Status)

send_resp( put_resp_content_type( conn,("application/json"), :ok, status ) ) end

With no Pipe Operator

Page 24: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

def index(conn, _params) do status = MicroStatus.version(Waffle.Status)

conn |> put_resp_content_type("application/json") |> send_resp(:ok, status) end

With the Pipe

Page 25: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Pattern Matching

x = 1

Page 26: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature
Page 27: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature
Page 28: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature
Page 29: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

If {:ok, contents} = File.read("file.txt") IO.puts contents end

Page 30: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature
Page 31: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

def max([head | []]) do head end

def max([head | tail]) do _max(head, max(tail)) end

defp _max(one, two) when one > two do one end

defp _max(one, two) when two > one do two end

Page 32: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Fewer nil checks

Fewer if statements

Eliminate early returns

Shorter functions

Much tidier code!

Page 33: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Even for single threaded programming, mutability brings an uncertainty about how a program will execute. And I do not miss the

mutability at all. Functional programming and immutability helps to clarify things and makes it easier to reason about code.

Lau Taarnskov, Tech Blogger

Page 34: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Mix

IEx

Logger

ExUnit

Page 35: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an

accident.

Devin Torres, Tech Blogger

Page 36: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Immature is a word boring people use to describe fun people.

Will Ferrell

Page 37: Drinking the Elixir - YOW! Conferences · Elixir is what would happen if Erlang, Clojure, and Ruby somehow had a baby and it wasn’t an accident. Devin Torres, Tech Blogger. Immature

Thanks!