Philly ETE Talk Notes: “Adventures in Elm: Events, Reproducibility, and Kindness”

One of the ETE talks I attended was called “Adventures in Elm: Events, Reproducibility, and Kindness”, by Jessica Kerr. She has several more talks available1

Elm is one of a number of languages that compiles to Javascript (Coffeescript, ScalaJS, ClojureScript, TypeScript, etc). It adds types and strict immutability, and an event loop that appears to take control of the entire page (you can call out to Javascript if you get stuck). From the outside this appears to me to be a bit similar architecture to using ClojureScript + Om + React.

Elm has a virtual DOM and event loop, which is familiar coming from having used React + my vague understanding of Redux / Flux. The event loop concept is neat, and there is a fairly well-known talk that shows the mind-blowing utility of this2, though I think that demo of Elm to make a game makes some people think it’s not for them.

The biggest problems I personally have currently with React on it’s own is that if I just write Javascript code, the only way to tell if it’s correct is to step through the code, and the architecture is nearly impossible to enforce, so is Elm is one of several potentially appealing answers.

To see an example of some Elm code, there is a utility that converts JSON to typed ELM objects3

import Json.Encode
import Json.Decode exposing4
-- elm-package install --yes circuithub/elm-json-extra
import Json.Decode.Extra exposing5

type alias Something =

decodeSomething : Json.Decode.Decoder Something
decodeSomething =
    Json.Decode.succeed Something
        |: ("" := decode_Unknown)

encodeSomething : Something -> Json.Encode.Value
encodeSomething record =
        [ ("",  encode_Unknown <| record.)

The compilation step is done through "elm make"6. There is also an elm-format7 that does auto-formatting for you like Scalariform. This which has some benefits, e.g. moving the argument about formatting into it's own little hole on the internet where you can safely ignore it. Apparently one of the goals of elm-format is to make source control history better by preferring more lines over longer ones, which is fantastic (as a counter-example, compare this to the combinable Scala imports, which make for a truly miserable merge process).

import a.b.c
import a.b.{c, d}

The Elm compiler also enforces semantic versioning, so you can safely depend on a version range. I don't know of another technology that has a feature like this to compare, it sounds like a great idea, although it's the sort of thing that could be challenging on a large project. Specifically this means you can add APIs in a point release, but not take them away, and depend on other people to do the same.

The compiler prevents circular dependencies at the module level, and even better, prevents you from directly accessing a transitive dependency without directly requiring it (one of the meta-themes of this year's ETE was "things you wish NPM had")

The compiler is designed to give error messages that help the developer, rather than punishing them. The inclusion of "kindness" in the title of the talk is a neat choice: collectively the tools in the Elm ecosystem are designed around kindness toward the programmer, a goal more tools should have.

  1. []
  2. []
  3. []
  4. := []
  5. |: []
  6. []
  7. []