Wednesday, 7 December 2016

You don't speak JavaScript

For some reason JavaScript is a language that even top programmers are not willing to learn and understand properly.
Joe Armstrong. The father of the Erlang language. The language that has concurrency in its core. I've just finished reading an article of Mr Armstrong in which he compares JavaScript's concurrency to Erlang's. Now, what can we expect from The Average JavaScript Programmer if this is what I've read?

You write something like this:
    var done  = function(x){ ... do something with x ..};
    var error = function(x){ .... x ...}
    read(Something, {onSuccess:done, onError:error});
    ... more code ...
Code like this melts my brain.

When the program is executing somewhere inside “_more code_”, the read completes, and I'm time warped back in time to the code in _done_, then back to wherever I came from in “_more code_” when _done_ completes. I find this very difficult to understand.
But what happens if an event is triggered in the time interval between removing an event handler and adding a new one.

No Mr Armstrong. That is not how JavaScript callbacks are executed :(