think like an elm developer piper niehaus
play

Think like an Elm developer Piper Niehaus Denver, CO, USA - PowerPoint PPT Presentation

Think like an Elm developer Piper Niehaus Denver, CO, USA Backpacker / skier Nonprofit board chair @piperniehaus Software Engineer at Pivotal Pivotal Tracker team Elm in Production since 2016 Internal Products and


  1. Think like an Elm developer

  2. Piper Niehaus Denver, CO, USA ● Backpacker / skier ● Nonprofit board chair ● @piperniehaus

  3. Software Engineer at Pivotal Pivotal Tracker team ● Elm in Production since 2016 ○ Internal Products and Services team ● Kotlin ○ @piperniehaus

  4. We all get excited about new languages @piperniehaus

  5. Production changes everything Bugs matter ● Testing matters ● Maintainability matters ● @piperniehaus

  6. Goals The promise (level set) ● The production hump ● What’s next? ● @piperniehaus

  7. Agenda About me ● The promise of Elm ● Background ○ Language ○ Architecture ○ The Pivotal Tracker experience ● Is Elm right for you? ● @piperniehaus

  8. Elm: A DSL for web apps Language ● Framework ● Ecosystem ● @piperniehaus

  9. Elm in production @piperniehaus

  10. Elm background Evan Czaplicki’s Harvard thesis ● Now at noredink ● Elm’s Benevolent Dictator For Life ● @piperniehaus

  11. Benevolent dictator for life Design ● Direction ● Priorities ● Pace ● @piperniehaus

  12. Agenda About me ● The promise of Elm ● Background ○ Language ○ Architecture ○ The Pivotal Tracker experience ● Is Elm right for you? ● @piperniehaus

  13. Elm language Elm is a programming language that compiles to JavaScript Pure functional ● Strong static type system with a friendly compiler ● @piperniehaus

  14. Agenda About me ● The promise of Elm ● Background ○ Language ○ Pure functional ■ Strong static type system with a friendly compiler ■ Architecture ○ The Pivotal Tracker experience ● Is Elm right for you? ● @piperniehaus

  15. What is a pure function? A function that takes some input and returns output without affecting or being affected by external state @piperniehaus

  16. Pure function Impure function Function (arguments) { Function (arguments) { External Computations Computations state } } Return Return value value @piperniehaus

  17. @piperniehaus

  18. Pure vs impure functional programming languages Pure functional languages: Languages that support only functional paradigms (Haskell, Elm) ● Impure functional languages: Languages that support both functional and imperative style ● programming (Kotlin, Python) @piperniehaus

  19. Benefits of pure functional programming Consistency ● Code is easy to follow and understand ● A function given the same values always has the same result ● Lack of race conditions ● Time travel debugger ● @piperniehaus

  20. Elm time travel debugger Because every function in Elm is pure ● See the system at any state ● Roll back, roll forward ● @piperniehaus

  21. Time travel debugging @piperniehaus

  22. Agenda About me ● The promise of Elm ● Background ○ Language ○ Pure functional ■ Strong static type system with a friendly compiler ■ Architecture ○ The Pivotal Tracker experience ● Is Elm right for you? ● @piperniehaus

  23. What is a type? An object’s type describes ● The kind of data in the object ○ What it can do ○ Examples: ● String ○ Int ○ All languages must check types ● Can’t do 1 + “two“ ○ @piperniehaus

  24. What is static typing? All languages must check types but statically typed languages check at ● compile time, while dynamically typed languages check at runtime. Example: Can’t do 1 + “two“ ● In ruby: we find this out when we try to load a page and see an error ○ In Elm: we can’t even compile our code to run the app at all ○ @piperniehaus

  25. Dynamic typing Types are checked at runtime Static typing Types are checked at compile time Strong static* typing Static typing with the goal of minimizing the gap between code that compiles and code that runs error-free @piperniehaus * While static is a definite CS term, strong is colloquial. This is our definition going forward.

  26. Strong static Dynamic Static typing typing typing Code compiles Code compiles Code compiles Code runs without errors Code runs without errors Code runs without errors @piperniehaus

  27. Strong static typing tools in Elm Extra checks to prevent runtime errors. EG: Custom types ● Null checks ● Exhaustiveness checks ● type Pet = Cat | Dog | Fish ○ Fido is a pet. ○ Everywhere we use fido, we must account for the possibility that fido could be a cat, a dog ○ or a fish @piperniehaus

  28. Benefits of strong static typing... Catches errors early and preempts null pointer exceptions ● Provides parameter + return type matching ● Makes impossible states impossible (no need to test them) ● Encode business logic into type system ● @piperniehaus

  29. For the developer, strong static typing means... Enables developers to focus on business logic ● Provides fast feedback ● Makes code easy to read ● Refactoring is easy ● @piperniehaus

  30. Elm’s friendly compiler Elm’s compiler messages are easy to read ● Makes it easy to rely on the compiler ● @piperniehaus

  31. Example, a misspelled function name Function addInts is defined Oops! We tried to call it but misspelled Compiler error is helpful and friendly @piperniehaus

  32. Agenda About me ● The promise of Elm ● Background ○ Language ○ Architecture ○ The Pivotal Tracker experience ● Is Elm right for you? ● @piperniehaus

  33. What is the Elm architecture? A way of building web apps that separates an application into: Model : the application’s current state ● Update : the only way that the state is updated ● View : the application’s current state in html format ● The elm architecture feels natural in Elm, but it also works in other languages Inspiration for Redux ● @piperniehaus

  34. Elm architecture example User makes a Message is sent to change in the UI update function (onClick) View Update New model is passed to view function and Update function rendered in the returns a new browser model based on Model the old model and function arguments @piperniehaus

  35. An example @piperniehaus

  36. @piperniehaus

  37. Benefits of the Elm architecture Single source of truth ● Easy to understand ● Removes race conditions ● Model and view stay in sync ● @piperniehaus

  38. Why use Elm? Language Architecture Pure + + Static typing Architecture functions = Few runtime errors @piperniehaus

  39. Agenda About me ● The promise of Elm ● The Pivotal Tracker experience ● Background ○ Types & FP in practice ○ Scaling ○ Testing ○ JavaScript interop ○ Is Elm right for you? ● @piperniehaus

  40. Elm and functional programming at Pivotal Tracker 2016 2017 2018 Dashboard New user Project Kotlin, RoR / Much in Elm experience Memberships TypeScript React / discussion in Elm Page in Elm experiments Backbone @piperniehaus

  41. Elm here! @piperniehaus

  42. The decision to use Elm Developers using Elm in personal projects ● Multiple meetings, much thought ● Would Elm stick around? ○ Interop between multiple languages? ○ Developers using multiple languages? ○ Started in an isolated piece of the app ● Not interconnected with other stuff ○ Easy to pull out if it didn’t work ○ @piperniehaus

  43. Projects The Dashboard page ● Learning curve ○ (Most) developers like it ○ Challenge of scaling an Elm app ○ Testing philosophies in Elm vs on our team ○ Expanded usage ● Testing hitting a stride ○ Challenge of interop with Javascript external libraries ○ @piperniehaus

  44. Continuing to use Elm mentalities Where else can we apply functional programming and strong types? ● More Elm? ○ TypeScript? ○ Kotlin? ○ @piperniehaus

  45. Agenda About me ● The promise of Elm ● The Pivotal Tracker experience ● Background ○ Types & FP in practice ○ Scaling ○ Testing ○ JavaScript interop ○ Is Elm right for you? ● @piperniehaus

  46. Elm lives up to its promise Runtime errors ● Race conditions ● Easy refactors ● Mindset change ● @piperniehaus

  47. Encoding business logic into types Example: Managing memberships Project member ● First name ○ Last name ○ Email ○ Invitee ● Email ○ @piperniehaus

  48. People @piperniehaus

  49. @piperniehaus

  50. Agenda About me ● The promise of Elm ● The Pivotal Tracker experience ● Background ○ Types & FP in practice ○ Scaling ○ Testing ○ JavaScript interop ○ Is Elm right for you? ● @piperniehaus

  51. How to structure a large Elm app? It depends™ ● One of the biggest hurdles and biggest FAQs ● Big files? Small files? ● Big update loops? Multiple update loops? ● ¯\_( ツ )_/¯ @piperniehaus

  52. Agenda About me ● The promise of Elm ● The Pivotal Tracker experience ● Background ○ Types & FP in practice ○ Scaling ○ Puzzle ■ Mindset ■ Testing ○ Is Elm right for you? ● @piperniehaus

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend