BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Reduce the Risk of Failure With Elm

Reduce the Risk of Failure With Elm

This item in japanese

Lire ce contenu en français

In a practical, try-it-for-yourself session at Strange Loop 2015, Richard Feldman showed how his team started using the Elm language to reduce the risk of failure and iterate faster on their web app.

JavaScript developers everywhere have likely encountered the error undefined is not a function. Feldman used this pain point to drive home Elm's ability to improve the developer experience. The Elm compiler will catch many errors that plague raw JavaScript developers. According to Feldman, in an Elm app, "once it compiles, it typically works on the first try with no regressions or runtime exceptions".

When I think about why I like using Elm and why it's such a nice user experience, it's just the little details, the little polish, the little pieces of user experience that make you feel great on a daily basis.

For those unfamiliar with Elm, it's a functional programming language created by Evan Czaplicki, designed to make it easy to build web UIs. It compiles to JavaScript and, like React, uses a virtual DOM to manipulate the interface. According to the Elm Blog, in one benchmark, it's dramatically faster than React.

Bar Graph of Runtime Speeds for TodoMVC app in various languages. Shows Elm as very performant.

Here's what the simplest example of Elm code looks like:

import Html exposing (span, text)
import Html.Attributes exposing (class)


main =
  span [class "welcome-message"] [text "Hello, World!"]

"Everything in Elm is one of two things: immutable data or stateless functions," says Feldman. This funtionalty purity (where the functions have no side effects) is nice in theory, but web developers often have to interact with many other systems. To get around this, Elm has what it calls "Tasks". Feldman says a task is "a data representation of stuff you want done; it's a list of instructions".

Elm can interact with existing JavaScript libraries using "ports". Developers can tip-toe into the Elm waters by swapping out pieces of their app with Elm code, connecting the two with a port.

A video of Feldman's talk is available on YouTube along with the rest of the sessions. Additionally, Feldman has written a tutorial post on using Elm to build a sign-up form.

Rate this Article

Adoption
Style

BT