Automasean

Book reflection: Programming Elm

Programming Elm by Jeremy Fairbank is a beginner-friendly book for learning Elm. I found it especially friendly coming from a JavaScript background. There are lots of helpful comparisons between JS and Elm implementations.

Another impressive aspect is that the author walks you through practices for refactoring and scaling an app in Chapter 3: Refactor and Enhance Elm Applications and Chapter 6: Build Larger Applications. This information is practical and is clearly demonstrated via examples.

Coding along while reading really allowed me to play around with the language and exercise its features. Following the examples helped me to retain the material but exploring beyond the samples in the book really helped connect the dots. The author does a great job of facilitating this absorption by sprinkling coding challenges along the way with answers available in the book source code materials.

Let's dive into some first impressions of the language.

Elm Architecture

The Elm Architecture seems well thought-out. Separating the Model, Update, and View logic keeps the code organized, modular, maintainable and easily extensible. Nonetheless, I felt that building upon the architecture became a bit verbose and slightly cumbersome on occasion. I plan to develop more with Elm to further experiment with this hypothesis.

Compiler

Compiler complaint comic

Don't you hate when a compiler yells at you for something and the message is so cryptic that you have no idea where to start? Sure, there are other debugging techniques but the point I'm trying to make is that I've never seen compilation errors as straight-forward and helpful as they are with the Elm compiler.

That being said, at times these straight-forward messages can become quite ubiquitous. This is a net positive characteristic in my opinion. Making significant changes before recompiling can result in a rabbit hole of compilation errors, which is unfortunate. However, this becomes a way to incentivize the developer to compile often following smaller changes. The developer also gets the peace of mind that comes with the satisfaction of the compile-time checklist. Elm makes the promise that the users of an Elm app will experience zero runtime exceptions.

This is a pretty big deal and it's only possible with the help of Elm's type system.

Type system

Elm is a strongly-typed language and, so far, the type system gets an A+ from me. Being able to use types like Maybe and Result is a game-changer coming from a JavaScript background. No more forgetting to check the existance of a constant. Not to mention type constructors, exhaustive pattern matching capabilities and JSON decoders.

REPL

When starting to code in Elm it quickly becomes apparent that the Elm REPL provides a large productivity boost. There's no need to scaffold code and jump through hoops to make the compiler happy just to test the result of an expression. Fire up the Elm REPL, test away, and move on.

Functional-first

Using only pure functions and being side-effect-free comes with a great deal of benefits. Tests become easy to write, logic becomes easily composable, cognitive overhead is reduced, etc. If interested, check out more thoughts on functional programming here.

JavaScript?

One of the most attractive features of Elm is the interoperability with JavaScript. Many people have incrementally adopted the language into existing applications. These folks have set a precedent. Their successful adoption of Elm can be part of a case study to start programming in Elm. It's much easier to apply a strangler pattern to a codebase than to try to re-write everything from scratch and flip the switch to a shiny new site.

Overall, Programming Elm is a worth-while read.