Update 11/28/15, 14:40 MST — Added some thoughts about how the type system helps eliminate runtime errors after a Twitter “conversation” with Evan Czapalicki, designer and developer of Elm.
For the past couple of days, I have been intensely (think 4+ hours/day on over my Thanksgiving holiday) teaching myself a newish programming language called Elm. My goal with this article is to organize my preliminary thoughts around Elm with the hopes that more front end developers will take a look at Elm and think about how they might benefit from using it in production.
According to the Elm website, Elm is “the best of functional programming in your browser”. When I read this claim for the first time, two things stuck out for me: “the best of functional programming” and “in your browser”. Why do these two things stick out for me?
The first one because I’ve realized that learning to program in a functional way is not only fun but it makes the code you write easier to understand, and thus maintain. You don’t have to go off the deep end of functional programming into the realm of monad burritos and category theory to find the benefits. Functional programming is working its way into “mainstream” languages such as Java, with the release of Java 8, so writing this style of code in production is even more likely now. Even my object oriented Java code is benefiting from the shift in thinking that studying functional programming has brought. I will leave the experiencing of these benefits as an exercise to the reader since they tend to vary from individual to individual. Some resources I might recommend to get you started are “Learn you a Haskell for Great Good” as well as some more “mainstream” resources such as “Functional Programming in Java”.
The second thing I am loving about Elm is the syntax. I have learned over the years that I am very sensitive when it comes to programming language syntax. The syntax of Elm is very close to that of Haskell with a dash of OCaml and F# thrown in for good measure. For some reason, I really like the syntax of Haskell so this is a huge win for me. If you are syntax sensitive like me and can’t stand Haskell syntax then I suggest you look elsewhere.
The third, and not necessarily final reason, is the focus on developer happiness and productivity. For those of you Rubyists out there, that should sound pretty familiar. There are many concrete examples of this mantra. The first and foremost are the compiler errors. I can only assume the amount of work that went into making the as great as it is. For more details, checkout out these two articles from the Elm blog:
I’ve been writing a small browser based implementation of Minesweeper as my laboratory experiment for this article and I have to say that the static type system , coupled with the compiler assistance, has made this journey to learning Elm a joy. I haven’t written a single test for this application, because I wanted to focus on producing something substantial, and haven’t missed them all that much. The old adage that says if you can make the type system happy then the program will just work seems to ring true in Elm. I am sure there are times when I will need to write tests to drive out some tricky logic but up to this point I haven’t missed them because I know the compiler and the type system have my back.
If you program in the browser for a living I highly suggest you give Elm a try by writing an application with it. The helpful type system, complete with type inference, coupled with great compiler errors make it a joy to work with. Couple that with the opinionated way of building applications, think of something very similar to Flux or Redux, and I think Elm is a no brainer for your next browser based applications.