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

Why you should care about Elm

Why you should care about Elm

Tereza Sokol

January 20, 2017
Tweet

More Decks by Tereza Sokol

Other Decks in Programming

Transcript

  1. Unfortunate circumstances Pressure from deadline Bad management Lack of team

    communication New on the team … Bad day 11 @terezk_a
  2. Mutation of state is the work of the devil, don’t

    do it!!!!! (but like ok, if you really need to then whatever) adasdfgsdafgsafgdsafhdvfsga dghf safgd sagfdh sfgad gfsad gfs fghas fgas fgsad fghas fgha desafg arjegrjhrhsgvrehskjggevhlragjvhrkagd jkhrg bdjhvgcnrldajvrjhfdgv sdjhxfgchjvgjkbscgjhkgncjhfdksgvjhkdfg nxghfdskcnjfhdcgnkjhgsdcngkjfhgsjfhgjhfshjkfgnkjsgkfhjdgsckhjfnsjfkgskjdfhjkcsnjkdfhsgcnjksgc njsjkgghjkfcnsjhkdncghjdfnscjhkgnjkfhdgskjhcnfsjhgcnfghjgnfhjkdsgcnfkjnsgshjkfdgncjhdfskncgh jfdckgnfksjhdcgnkjhfsncjhgfnsjhkcnhjsg Type checking, but only like sometimes, great ¯\_(ツ)_/¯ hlp pls wat 15 Unidirectional data flow, yay more stuff @terezk_a
  3. What are we even trying to do? State View Event

    Event => State Timer, mouse position etc. Event 22 @terezk_a
  4. What are we even trying to do? State View Event

    Event => State HTTP request, other async stuff Event Timer, mouse position etc. Event 23 @terezk_a
  5. You can do anything in JavaScript View Message Update Commands

    Message Subscriptions Message 26 @terezk_a Model “I’ll fix it later” Mutated, unclean
  6. Pure and impure functions // Impure function function addOne(x) {

    x++; fireMissiles(); } // Pure function function addOne(x) { return x + 1; } 30 @terezk_a
  7. Pure functions and immutability // JavaScript ✨ // (anything goes)

    var x = { foo: ”bar” } var y = f(x) -- Elm -- (only pure functions) x = { foo = “bar” } y = f x 31 x is always unchanged What is x? ¯\_(ツ)_/¯ @terezk_a
  8. Static types and type inference -- With function signature horizontalGrid

    : List GridAttr -> PlotElement msg horizontalGrid attrs = Grid (List.foldr (<|) defaultGridConfig attrs) -- Without function signature horizontalGrid attrs = Grid (List.foldr (<|) defaultGridConfig attrs) 33 @terezk_a
  9. No run time errors???? dostoevsky = { firstName = "Fyodor”

    , lastName = "Dostoevsky” } greet person = "Hello " ++ person.firstname main = text (greet dostoevsky) 36 The compiler The program @terezk_a
  10. Constrains Rules • Only pure functions • Static type system

    • Opinionated on architecture Benefits • No run time errors! • Enforced semantic versioning • Improved performance • ⏳ Time traveling debugger! 42 @terezk_a