Elixir - Easy fun for busy developers @ Devoxx 2016

56
#Devoxx #AwesomeElixir @koenighotze Bootstrap |> Elixir EASY FUN FOR BUSY DEVELOPERS

Transcript of Elixir - Easy fun for busy developers @ Devoxx 2016

Page 1: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Bootstrap |> Elixir

EASY FUN FOR BUSY DEVELOPERS

Page 2: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

@koenighotze / David Schmitz

Senacor Technologies Programmer!

Bad, bad fighter!

Page 3: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

WET YOUR APPETITE FOR ELIXIR SHOW OFF SOME COOL FEATURES

CODE A DISTRIBUTED PIZZA PARLOUR

Page 4: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

学⼀一⻔门语⾔言,就是多⼀一个观察世界的窗户。To learn a language is to have one more window from which to look at the world

Page 5: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Two minor caveats

Page 6: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

I AM THE JON SNOW OF ELIXIR AND ERLANG/OTP

Page 7: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

THIS IS NOT A README!

Page 8: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

YET ANOTHER PROGRAMMING LANGUANGE?

Y A P L

Page 9: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Elixir in a Nutshell

+Elixir in a Nutshell

+

Page 10: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Principle of Conciseness Principle of Consistency Principle of Flexibility

Why Ruby is awesome

Page 11: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Battle-proven BEAM and OTP

Ever seen WhatsApp crash?

Reactive before Reactive-is-HipTm

Actors before Actors-are—HipTm

Why Erlang is awesome

Page 12: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Why Clojure is awesome

Because Rich Hickey is always right

Page 13: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

WHY NOT JUST USE RUBY, ERLANG OR CLOJURE?

Page 14: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

It didn't take long, but pretty soon my gut feeling kicked in. This is good $hit. …, they both compile to instructions for the EVM

- Joe Armstrong (Creator of Erlang)

Page 15: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Programmer focussed OTP Power + Ruby Love Functional but pragmatic

Standard Toolset

Why Elixir is awesome

Page 16: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Page 17: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Erlang/OTP

ERLANG/BEAM TOOLS

LIBRARIES PATTERNS

Page 18: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Elixir

ERLANG/BEAM TOOLS

LIBRARIES PATTERNS

Page 19: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Pizza Parlour - Version 1“Take my money! I want a salami pizza!”

“I am hungry!!”

“3 €, please!”

Page 20: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Pizza Parlour - Version 1 Demo

Page 21: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

WHAT ABOUT 99.9999999?

Page 22: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Pillars of Resilience and ReliabilityMessage-passing between

isolated processes Automatic recovery and

monitoring Transparent distribution

Page 23: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Elixir Power Tools

Messaging with GenServer modules Supervisor for transparent resilience

Page 24: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Shared resources Shared state Shared stability

SHARED STATE

COMPUTATION COMPUTATION COMPUTATION

HEAVY WEIGHT PROCESS

COMPUTATION COMPUTATION COMPUTATION

Page 25: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Light Weight Processes

MAILBOX

STATE

COMPUTATION

AsynchronousSynchronous

GENSERVER

Page 26: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

GenericServer in a Nutshell

loop(current_state): wait for message handle message send reply loop(new_state)

Page 27: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

GenericServer in a Nutshell

loop(current_state): wait for message handle message send reply loop(new_state)

Page 28: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

GenericServer in a Nutshell

loop(current_state): wait for message handle message send reply loop(new_state)

Page 29: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

GenericServer in a Nutshell

loop(current_state): wait for message handle message send reply loop(new_state)

Page 30: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Architecture build around tiny Processes

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

PROCESS

HEAVY WEIGHT PROCESS

Page 31: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Message driven Pizza - The request{:pizza, “Salami”}

handle_call({:pizza, “Salami”}, from, state)

Page 32: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

%{order_number: 123, price: 10.50}

Message driven Pizza - The reply

Page 33: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Pizza Parlour - Version 2 Demo

Page 34: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

NOW REALLY, WHAT ABOUT

RESILIENCE???

Page 35: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

“HAVE YOU TRIED TURNING IT OFF AND ON AGAIN?”

Page 36: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

The WHAT IF scenario

{:pizza, “Salami”}

Page 37: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Risk at the Bottom of the Supervision TreeAPPLICATION

SUPERVISOR

Here be dragons…

Page 38: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

APPLICATION

SUPERVISOR

Supervisors watch their Children

Page 39: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

APPLICATION

SUPERVISOR

Supervisors watch their Children

Page 40: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

APPLICATION

SUPERVISOR

Supervisors watch their Children

Page 41: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Pizza Parlour - Version 3 Demo

Page 42: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

There is so much more

Page 43: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Protocols for polymorphism

defimpl String.Chars do def to_string(bitmap), for: [Bitmap] do … end end

Page 44: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Hygienic Macrosdefmacro unless(clause, do:expression) do quote do if(!unquote(clause) do unquote(expression)) end end end

Page 45: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Hygienic Macrosdefmacro unless(clause, do:expression) do quote do if(!unquote(clause) do unquote(expression)) end end end

Page 46: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Zero downtime Hot code replacement

def code_change(ver, old_state, extra) do new_state = … {:ok, new_state} end

Page 47: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Real-time apps with Ecto and Phoenix

defmodule Video do def alphabetical(query) do from q in query, order_by: q.name end end

Page 48: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Real-time apps with Ecto and Phoenix

def alphabetical(query) do …

Video |> Video.alphabetical |> Repo.all

Page 49: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

SHOULD WE ALL START BUILDING EVERYTHING

WITH ELIXIR?

Page 50: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Page 51: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

WELL….MAYBE NOT?!

Page 52: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

AND OF COURSE…

Page 53: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

MICROSERVICE AND CLOUD READY ;)

Page 54: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

New insights and ideas Clean patterns as part of the core Architecture and Tooling for IoT Vibrant and friendly Community

Come for OTP, stay for…

Page 55: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Elixir Homepage, http://elixir-lang.org/

Dave Thomas, Programming Elixir

Fred Hebert, Stuff Goes Bad: Erlang in Anger

Do you want to know more?

Page 56: Elixir - Easy fun for busy developers @ Devoxx 2016

#Devoxx #AwesomeElixir @koenighotze

Thank you very much!<[email protected]>