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

The ELM Architecture

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers.

The ELM Architecture

Avatar for Swift India

Swift India

May 25, 2019
Tweet

More Decks by Swift India

Other Decks in Technology

Transcript

  1. LET’S TAKE A STEP BACK… IMPERATIVE APPROACH ▸ Telling program

    how to solve the problem ▸ Step by step procedures ▸ Series of statements ▸ Use case driven ▸ Defines Object ▸ May have side effects ▸ Easy to debug stepwise ▸ C++, Java, Swift
  2. NOW LET’S LOOK AT… DECLARATIVE APPROACH ▸ Telling program what

    to do exactly ▸ Declare what the end result is ▸ Series of expressions ▸ Constraint driven ▸ Defines functions (first-class & higher order) ▸ Comparatively lesser side effects ▸ Same input —> same output ▸ Scala, Haskell, Lisp, Elm, Swift
  3. WHY IS SWIFT IN BOTH APPROACHES…? IN SWIFT ▸ Everything

    is a closure ▸ That means we do functional programming using closure
  4. COMING BACK TO THE TOPIC…? ELM ▸ is a programming

    language for web ▸ is completely based on declarative approach
  5. HOW DOES ELM WORK? Elm Runtime / External Entities &

    Actions Update Virtual Views Model command / message updates model (ideally creates) updated model is passed to views Model: Record/Data Cmd Msg: Type update(cmd, model) -> (cmd) view(model) -> (view-msg)
  6. WHY ELM ? ADVANTAGES: ▸ Consistent state management ▸ No

    runtime exceptions ▸ Declarative ▸ Immutable Models ▸ All other pros of a functional program
  7. WHY NOT ELM ? ▸ If you need to change

    a value deep inside a nested data structure, you can't simply read the value and mutate it, as you could in imperative approach ▸ If you are from OOP background: ▸ feels very restrictive ▸ for loops replaced by higher order functions DISADVANTAGES:
  8. IF I AM NOT WORKING WITH THIS THEN… ? ▸

    Experience of working in an alien for a little bit is also fruitful ▸ Learn to deal with purity, immutability (functional) ▸ Constraints will push creativity ▸ Strategies in other approaches ▸ Functional Programming is different WHY LEARN?
  9. MY PRESENTATION IS… BASED UPON ▸ The Complete Bundle (Swift):

    ▸ https://www.objc.io/books/bundles/complete- collection/ ▸ https://github.com/objcio/app-architecture ▸ https://github.com/chriseidhof/tea-in-swift ▸ The ELM Language: https://guide.elm-lang.org/
  10. OTHER WORKS ON… DECLARATIVE APPROACH IN SWIFT ▸ CocoaWithLove -

    CwlViews: https:// www.cocoawithlove.com/blog/introducing-cwlviews.html ▸ React and Elm Inspired framework in Swift - https:// gist.github.com/inamiy/ bd257c60e670de8a144b1f97a07bacec ▸ The SAM Pattern ▸ http://sam.js.org/ (Original javascript library) ▸ https://github.com/fe9lix/SAM-Swift (Swift framework)
  11. REFERENCES… VIDEOS ▸ Yasuhiro Inami: Elm in Swift talk -

    https:// www.youtube.com/watch?v=7TJBbUFpsvE ▸ Sam Ritchie - Using the Elm Architecture in Swift - https:// www.youtube.com/watch?v=iiXAWcNkIbw ▸ A Peek into Elm Architecture - https://www.infoq.com/ presentations/elm-architecture ▸ An Introduction to Elm's Features and Architecture - https://www.youtube.com/watch?v=vgsckgtVdoQ
  12. CONNECT WITH ME… ▸ Twitter @itsdamslife ▸ Github https://github.com/itsdamslife ▸

    Today’s demo source code ▸ https://github.com/itsdamslife/ELMTimer