Skip to content
This repository has been archived by the owner on Feb 11, 2024. It is now read-only.

Latest commit

 

History

History
45 lines (31 loc) · 3 KB

Introduction.md

File metadata and controls

45 lines (31 loc) · 3 KB
  • Elm is a typed pure functional programming language that compiles to JavaScript
  • It was created specifically for Web Development (It is not a general purpose language)

Why use elm?

(From the point of view of a JavaScript developer with little prior experience about funcional programming)

  • No runtime errors in the browser

    • No such thing as null values or try...catch
    • Maybe and Result forces you to account for all possibilities, otherwise the code will not compile.
    • The compiler can also help you with friedly error messages and hints and it is great when refactoring.
    • Unit tests are still important. The compiler will avoid formal errors, but can not guess what you are trying to do!
  • Immutable data

    • In JavaScript it can sometimes be handy to mutate the data, but this can open up to unespected and nasty bugs, and sometimes it is even difficult to tell if you are actually mutating the data or not.
    • Forcing immutability in JavaScript in a consistent and efficient way is possible (see for example immutable.js), but it's one more thing to know about and it's easy to back out of it in any moment.
    • Whith elm you get immutable data out of the box.
  • Pure functions

    • All side effects are managed by the elm runtime through commands.
    • Inside an elm application you only deal with pure funcions. Calling the same function with the same arguments will always return the same value.
    • This also makes testing very easy.
  • You can introduce elm into your app progressively

    • No need to make a big commitment at the beginning. You can try it out on small parts of your application and see how it works out.
    • Elm can also communicate with JavaScript via ports. Handy if you need some functionality from an external JavaScript library.
  • Elm will make you a better JavaScript programmer

    • Helps you to be more disciplined
    • Helps you to better understand some of JavaScript worst pitfalls

The elm architecture

  • MODEL: the state of your application
  • VIEW: a whay to view the state as HTML
  • UPDATE: a whay to update the state

The update and the view functions are never called directly within our application. Instead, we sent messages and commands to the elm runtime.

Redux is inspired by the elm architecture

This is a representation of the elm architecture flow from the http example on the elm website. The main entry point is Html.program and the init function passes both an initial state and a command.

The elm architecture flow