tomasz kowal - lambda days€¦ · elixir and elm – the perfect couple tomasz kowal. i hate...

44
Elixir and Elm – the perfect couple Tomasz Kowal

Upload: others

Post on 25-May-2020

4 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Elixir and Elm – the perfect couple

Tomasz Kowal

Page 2: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

I hate language comparisons

The Blub paradox

Page 3: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Power continuum

Page 4: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available
Page 5: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

- interactive frontend- available backend

Page 6: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

"it is, all other things being equal, a mistake toprogram in anything but the most powerful

[programming language]” - Paul Graham

Page 7: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

"it is, all other things being equal, a mistake toprogram in anything but the most suitable

language for the problem domain”- Tomasz Kowal

Page 8: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Objective measure

„number of things, you need to keep in mind tounderstand given code fragment”

„programmers memory consumption”PMC

Page 9: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Functional languge

def function(arg1, arg2) do

  value = some_computations(arg1)

  another_value = some_computations(arg2)

  value + another_value

end

Page 10: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Functional languge

def function(arg1, arg2) do

  value = some_computations(arg1)

  another_value = some_computations(arg2)

  value + another_value

end

Page 11: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Functional languge

def function(arg1, arg2) do

  value = some_computations(arg1)

  another_value = some_computations(arg2)

  value + another_value

end

Page 12: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Functional languge

def function(arg1, arg2) do

  value = some_computations(arg1)

  another_value = some_computations(arg2)

  value + another_value

end

PMC = 4

Page 13: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

OO Language

def method(arg1, arg2) do

  value = some_computation(arg1 + property1)

  property2 = some_computation(arg2)

  value + property2

end

Page 14: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

OO Language

property1

property2

def method(arg1, arg2) do

  value = some_computation(arg1 + property1)

  property2 = some_computation(arg2)

  value + property2

end

Page 15: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Building frontend

"modifying document object model by reacting toevents from user and server"

Page 16: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Frontend programming

$(document).ready(function(){

    $("p").click(function(){

        $(this).hide();

    });

});

Page 17: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Frontend programming

$(document).ready(function(){

    $("p").click(function(){

        $(this).hide();

    });

});

Page 18: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Frontend programming

$(document).ready(function(){

    $("p").click(function(){

        $(this).hide();

    });

});

Page 19: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Frontend programming

$(document).ready(function(){

    $("p").click(function(){

        $(this).hide();

    });

});

Page 20: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Everything that is syntactically legal that thecompiler will accept will eventually wind up in your

codebase.- John Carmack

Page 21: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Signals

tHTML

HTML’

HTML’’

Page 22: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Signals

tHTML

HTML’

HTML’’

User input

Server event

User input’

Page 23: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Signals

tHTML

HTML’

HTML’’

User input

Server event

User input’

model

model’

model

model’’

update

Page 24: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Signals

tHTML

HTML’

HTML’’

User input

Server event

User input’

model

model’

model

model’’

update view

Page 25: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Signals

tHTML

HTML’

HTML’’

User input

Server event

User input’

model

model’

model

model’’

update view

Pure functions!

Page 26: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Single data structure holds entire applicationstate.

Page 27: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Backend programming

Page 28: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Backend programming

Page 29: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Backend programming

Page 30: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Backend programming - netsplit

Page 31: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Actors

msg

actor actor’

(queue msg)

t

Page 32: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Actors

msg

msg’

actor actor’

process msg’

(queue msg)

other msg process other msg

t

Page 33: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Actors

msg

msg’

actor

other msg’

actor’

process msg’

process msg

(queue msg)

other msg process other msg

t

(/dev/null)

Page 34: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Actors

msg

msg’

msg’’

actor

other msg’

actor’

process msg’

process msg

(queue msg)

other msg

(/dev/null)

process other msg

t

(/dev/null)

Page 35: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Actors

msg

msg’

msg’’

actor

other msg’

actor’

process msg’

process msg

(queue msg)

other msg

(/dev/null)

process other msg

t

(/dev/null)

Is actor alive/reachable?Notify on deathKill from outsideKill and restart group of actors

Page 36: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Elixir

def function(arg1, arg2) do

  val = receive msg of

    {:msg, msg} -> msg

  end

  val + arg1 + arg2

end

Page 37: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

CAP

Page 38: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available
Page 39: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

conn |> endpoint |> router |> pipelines |> controller

conn |> controller |> common_services |> action

Page 40: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

- Single data structure (source of truth)- flow in one direction

Page 41: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Things to remember #1

Different programming languages solve differentproblems.

Page 42: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Things to remember #2

For interactive web applications check out bothElixir and Elm

Page 43: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Things to remember #3

If you like this talk, follow me on Twitter@snajper47

Page 44: Tomasz Kowal - Lambda Days€¦ · Elixir and Elm – the perfect couple Tomasz Kowal. I hate language comparisons The Blub paradox. Power continuum - interactive frontend - available

Elm lang homepage: http://elm-lang.org/Elixir lang homepage: http://elixir-lang.org/Phoenix framework: http://www.phoenixframework.org/My blog: http://tkowal.wordpress.com/

Review: Krzysztof Wende