elm promises no run-time errors!

For the past several weeks I’ve learned the great language of Elm and I would like to share why I think it is so promising and capable of influencing the future of web development.

Elm is a functional front-end programming language, that compiles into JavaScript and promises big things, 2 of which are:

  • Great performance
  • No run-time errors

It is still pretty new, but has been used in big production apps, and kept it’s promises. For instance NoRedInk has 36k lines of Elm, as it is reported in elm’s official page.

Great Performance
Like reactJS, Elm uses a virtual DOM in order to optimize page loading. Here are some statistics regarding the speed of Elm.

It seems to beat the greatest web technologies. You can read and review the methodology if you feel skeptic, here.

No run-time errors
Elm uses something that is called type inference to insure no exception invokes to the user. In simple terms, elm will check every condition in your code and make sure that all the possibilities are fully covered. Imagine that JavaScript could tell you that you forgot to check if a variable is undefined, it is not so far from what elm does.

Pure Functional
I personally feel that slowly programmers start to realize that OOP is not so good as once we used to think. This is due to encapsulation, which is one of OOP’s core principles. Encapsulation is the binding of data and functions together as one structure we call Object. Very briefly it is bad due to unexpected state changes. When a programmer in OOP writes a method that alters the object’s state, he has to keep in mind that there may be other methods that alter the state as well, methods he didn’t know exists in many cases…

Elm deals with this issue with various ways. First of all there are no objects. There are Data Types and there are Functions and they are fully separated. Second, every variable in Elm is immutable , meaning it cannot be changed after declaration. This prevents the unexpected side-effects that can alter the variable without a programmer’s awareness. Moreover it causes one to carefully think before he gives a name to a variable. I find it also empowering the = operator. For example if we say in elm that
a = b + c
it means that without doubt, no matter what happens in the program, a will always be equal to b + c. One cannot say that on JavaScript because a line after c could be assigned to some other value, and thus it breaks the equation.

One powerful syntax
As a web developer one must learn the syntax of HTML, CSS and JavaScript. But also, one must know the weaknesses of each language. For instance, HTML has no conditions or loops, solutions to this have been suggested since PHP days when one could open a PHP block inside an HTML content. This damages the code readability because one needs to read both languages mixed together in order to understand what is going on. In Angular, for example, Google tried to solve this issue by embracing the HTML’s syntax and so one can use the <ng-if> directive, but I don’t find it as a good solution because when a heavy angular logic is being implemented in directives it gets messy pretty quick. Elm’s approach is quite neat, Elm provides a one unified syntax that covers JavaScript aspects as well as HTML and CSS all together.

Continue next to From JavaScript to ELM – Step 1: Basics

Future content in the blog
In the next posts I’m going to cover aspects of elm coding from the point of view of an average JavaScript developer. My goal is to bring you to the level of simple game development. like this one that I implemented (use w,a,s & d).

The only way to make sense out of change is to plunge into it, move with it, and join the dance.

Alan Watts


Liked the article?


Leave a Reply

Your email address will not be published. Required fields are marked *