How I learned Elm

Published Dec 14, 2017Last updated Apr 19, 2018

About me

Everyone knows me as LB, my background is in implementing cloud software solutions. Sometimes that looks like an integration between Google Spreadsheets and a company's accounting platform exports. Other times that looks like fully custom software built with frameworks such as Meteor in Node.js or Django in Python. I love it when something can be implemented in a way that empowers the organisation to use it and continue to maintain it themselves, rather than relying on external ongoing support or bug fixes.

Why I wanted to learn Elm

In late 2016 I had been reading a lot about functional programming, at first I did not really understand it fully and could not resolve the concept of 'no effects' in my head. I could not see how a language could work without effects, as that is what a programming language is meant to do, write to a database or print some output.

I did several tutorials in Clojure, Elixir and Elm to see what it was like to use these types of languages and read up a lot on Lisps and the history of functional programming and how it started.

I really wanted to see if the hype matched reality when using functional programming and if it changed the way I thought about programming in general. I also knew that just using functional paradigms in Python or Javascript were not enough.

How I approached learning Elm

I started with exploring functional languages broadly, seeing what was popular and reading more abstract articles (including Wikipedia) to get my head around some of the concepts.

At first I started to approach Javascript in a more functional way and worked through these resources:
http://eloquentjavascript.net/ - sections on Functional approaches
https://medium.com/javascript-scene/the-two-pillars-of-javascript-pt-2-functional-programming-a63aa53a41a4
https://drboolean.gitbooks.io/mostly-adequate-guide/content/

Then I dug into the world of just functional languages and worked through the following tutorials:
https://www.elm-tutorial.org/en/
http://clojurekoans.com/
https://bigmachine.io/products/take-off-with-elixir

Finally I stepped into both Elixir and Elm a bit more as they felt nicer to use and seemed to make more sense, they also both had nicer errors when I made the inevitable mistakes.

I then made two small personal projects in Elixir and Elm to get more of a sense of how to do something beyond the basic online examples and tutorials.

After all of that, I had the chance to use Elm in a real company project as we wanted to implement a complicated user interface and Jquery was not up to the task.

Challenges I faced

There are a lot of functional language specific terminology that really made it hard, and most of the tutorials seem to assume you have some knowledge of this world before learning anything.

There were a bunch of new terms such as currying, monads, pure (and non-pure) functions, composing, imperative vs declarative coding.

Further to that, each language itself has its own terms for their primary types, package managers and popular libraries for common tasks (such as handling dates and times).

The hardest thing is keeping motivated while you run into these roadblocks, not getting too frustrated and knowing when to stop, maybe go to bed, and come back to the problem tomorrow.

For Elm specifically, the language itself is still young and has some rough edges, the main being code changes over the last 12 months meaning that some tutorials use older syntax that is not recommended in the latest versions.

Elm also has strong typing, the language itself makes the transition easy and assumes you come from a dynamic typing language (Javascript). This was a bit hard to work with initially and felt restrictive, after using it for a while I found that this is incredibly helpful and ensures you write more reliable programs.

Key takeaways

Elm is a great functional language to use on the front end, it replaces the need for React and a state management tool and forces you to write code that is a lot harder to break.

Elm has a steep learning curve, especially if you have had no experience with purely functional languages, the curve is worth it and is steep but short.

Elm is really easy to get into an existing project and works alongside Jquery or React but can also replace what they do in a better way.

You do not need to know another functional language to use Elm, but reading about some of the concepts in a language agnostic way helps a lot.

Elm is really fun to use, and works incredibly reliably once you have it up and running in your frontend.

Tips and advice

Read broadly about functional programming languages and decide for yourself if these ideas resound with you:
https://drboolean.gitbooks.io/mostly-adequate-guide/content/

Take the time to go through the Elm tutorials:
https://www.elm-tutorial.org/en/
https://guide.elm-lang.org/

Build something small and simple in an existing project, either your own or a company one but something where you have a good idea of what the final output looks like.

Final thoughts and next steps

I love learning new things, I always find it helps me see my existing world in a fresh way. Personally, I have found that some of the habits from the functional world help me write better Python code. For example, I now write simpler, but more functions on my classes where each returns a simple data structure of a dict, list or tuples and only do affects at the last possible point (eg. writing to the database or writing to a response).

I do hope to use Elixir in a larger project and see how that is like to use, maybe even with Elm on the frontend.

Discover and read more posts from LB (Ben Johnston)
get started