My feeling about Elm
I do not remember when heard about Elm for the first time but is been an year and a half since I began to play with it, every few months I spent 1–2 weeks learning and making some small app and each time felt so different from my everyday job. So I wrote this to share some thoughts about it.
The things I love:
Elm compiler is awesome
I do not have many experiences compiled languages but I love the way compiler shows errors, it is most helpful compiler I ever have seen. The errors are in understandable language, very clear and the compiler shows how to fix them or provides links to documentation.
Elm is not just a language
Elm is also kind of framework, it comes with the elm architecture, which is the only way can write code, when you get used to that is really easy. If you are familiar with Redux, briefly the elm architecture is jus that. You have a model ( your app state ), a view which is shaped based on your model, from the view you can send a messages ( actions ) to update function which change the model and finally every time your model is updater automatically your view is updated as well. May sound confusing but once you see it at action will click immediately
Onboarding new people should be easy, as already said there only one way of doing things, it doesn’t matter how big your project is, everything comes down to the elm architecture. I heard that some people are able to push to production after few hours.
Strive to isolate side effects
Elm ( as other FP languages ) drives you to isolate side effects in specific place of your program, so when you have a bug is easy to find, it’s over there in that dirty corner of the app.
The things I still don’t like ( or understand )
Decoding JSON is terrible:
If you have ajax call which returns a big nested JSON be ready to spend hours writing decoders. Additionally, encoders/decoders for me are the most difficult part that I had to learn.
Communication with Browser api is long game:
If you want to use a browser api like localStorage or ServiceWorker, good luck with that, you have to write some JS and connection between Elm and the JS which means sending and receiving data between Elm and JS. In a small project, I ended up with writing almost the same amount of JS code as Elm one.
In general, Elm is really verbose language, sometimes things in JS are like 10 lines of code and same in Elm is 100, so be prepared to spend time.
Why I am doing this to myself?
I have heard some people doubting about feature of Elm, for how long is going to stay here, is it going to die after few years and this kind of things. Shall I spend time for it? Is it worth it to learn? My answer is: even Elm disappear after few years ( something that I don’t believe ) its definitely worth it to learn it, you will become a better developer, you will learn pure functional programming, will start thinking in a different way. I have become a better developer since that, I enjoy coding much more and fill more confident writing in my daily job ( mainly JS, yep I am one of those ).
Elm helped me a lot with understanding things like currying, composition and side effects. Actually, I started to hate JS for the fact that it not immutable and functions are not auto curried by default, I started to miss things like pattern matching and pipe operators ( fortunately there are tc39 proposals for those ). I started to doing typed JS ( FlowType ) in order at least go close to Elm ( with Redux which is inspired by Elm )
Note: I am not Elm developer, and do not have any code in production (yet), my opinion is based on playing with the language in spare time while trying to learn the basics of functional programming.