10 reasons why you should give Elm a try

1 — Elm is fast and easy to learn

In Elm you don’t have dozens of language paradigms. Elm creators took the best things about functional programming and they put it together to make something usable.

Elm is addictive. As soon as you begin using it, you want to do more of it, and more and more. It feels like Ruby on Rails at the beginning. So powerful, and so addictive.

It is fast to learn, but it’s also very interesting, because the paradigms are few, but not at all basic. And the language is not taking a huge part of the creativity. For example, you can easily redefine operators if you want to.

2 — Elm syntax is compact and expressive

Elm doesn’t implement objects and classes, but prefer the types and types aliases, which is really an AMAZING alternative. With a little training, you can read Elm code like a novel.

It is almost impossible to do more than one assignment in a function. You can do it with a let … in … block, but then you can extract the assignment in other functions, so by default, you are doing only one-liners and that’s pretty.

3 — Pipes are beautiful

Pipes are a way to call a function on a variable, but in a more object-oriented way.

For example, in my little game, I could call handleWinning on game (in the example on the left), but I prefer doing game |> handleWinning, since it’s a lot more readable and I can chain functions on the same value (game).

But when it’s more expressive, you can apply functions to lists like in the isLoosing function : enemies |> any (Character.collision character) means. Take my enemies (inside my game) and apply the any function (of the List package) and returns true if any of my enemies enters in collision with my character. Character.collision character is a partial function since it requires normally two arguments, but the second is given by the pipe and the any function at first it’s a lot simpler to see things as functions, for example :

List.any (Character.collision character) enemies

It seems complicated at first, I admit, but it’s so powerful, simple and expressive when you are used to it that it’s worth it. And it removes completely the utility of OOP as we are used to it. It’s just magical.

4 — The Elm Architecture (TEA) is the current best way to do front end development.

For the people in love with React and Redux, I have good news for you, the Elm architecture is just React + Redux, but … in better shape !

If you like Rails for the MVC pattern, and you hate all the front end stuff because you find it too complicated and often error-prone, give TEA a try, you’ll love what you can do with it. It’s all about maintainability.

I tried vanilla Javascript, ExtJs, Prototype, Scriptaculous, Mootools, Backbone, Angular, Ember, and a lot other javascript libraries I even don’t remember, and I must say that Elm and TEA is fresh air.

5 — Elm documentation is wonderful

The Elm Architecture Guide is refreshing as a programming guide. Especially for front end development. You’ll learn much about purely functional programming and highly-typed languages in that guide that you will change your way of thinking about programming.

6 — Forget about runtime exceptions

Exceptions are inexistant in Elm. Yep, you read well. You’ll never see a “undefined is not a function” in Elm. The language is designed for you to tackle the bad things BEFORE they could even happen in real life. And that is amazing. For example, if you fetch JSON from a server, you’ll have to handle if the server didn’t answer correctly without ever worrying about bad data coming to your app.

7 — Fast to compile, fast to execute

When you recompile your Elm project (by simply reloading your web browser), everything is compiled and transpiled in JavaScript. You might think that it would be slow. But it takes less than a breath to compile an Elm project. So fast you even don’t see it.

8 — Everything is a pure function, so every test is a unit test !

Forget about integration tests, used to test a “global state”. There aren’t any in Elm. There are pure functions that take arguments and return values, and they don’t do anything with the current scope (there is no “this” or “self” in Elm) and the global scope.

If you are used to Capybara or PhantomJs, you can just … forget about all that. To test your Elm programs, you only have to write unit tests for your Elm functions. That’s it. When I say everything is pure functions, that also includes html tags.

Pure functions everywhere sounds unrealistic when you are used to javascript where most everything depends on the surrounding scope and looks like globals.

My test file

9 — Elm is used in the best front end intensive projects I have seen

A web project to teach grammar to kids, an ABC notation (music) editor and player and a sailing game are crazy projects in terms of front end maintenance and complexity… I guess safety of functional programming compared to JavaScript allows people to do amazing things. I never saw this level of ambition in vanilla JavaScript apps.

Remember the struggle to find a little date picker widget in js ? Now you can code that in Elm easily. You don’t need to import all the dependencies of jQuery UI + jQuery or another bigger framework.

10 — Elm is fun

But all of that being said, what is crazy in Elm is how fun it is. When I ported my little game from ruby to Elm, it was like I rediscovered programming. Some imperative programming basics like random number generation are a little more complex in a purely functional world, but functional programming allows more flexibility when it comes to reusability of the functions you create.

Conclusion

There are a lot more reasons to develop in Elm : Elm creator Evan Czaplicki is interesting and ambitious, the compiler error messages are helpful and fun.

I want to do more with Elm and I plan to create a course on the Elm basics. If some of you are interested, don’t hesitate to subscribe to my new posts on Medium.

Elm is SO amazing that we organize Elm Europe ! elmeurope.org