node.js - react - tj holowaychuk wikipedia




TJ Holowaychuk's criticisms of NodeJs (2)

Back story, read: https://medium.com/code-adventures/4ba9e7f3e52b

TJ says node fails because:

  1. you may get duplicate callbacks
  2. you may not get a callback at all (lost in limbo)
  3. you may get out-of-band errors
  4. emitters may get multiple “error” events
  5. missing “error” events sends everything to hell
  6. often unsure what requires “error” handlers
  7. “error” handlers are very verbose
  8. callbacks suck

Can someone inform on the issues TJ mentions? For example, I've never seen problems with callbacks being double-executed. Under what conditions would it/they occur?

EDIT For those voting to close: If you don't know who TJ is, he's responsible for the majority of npm modules. So this isn't "idle" ranting by an uninformed user. His departure will greatly hurt nodejs and this question attempts to get answers as to specifics of the criticisms. I never see these issues. Do you?


1: can happen, when you wrap a stream in a function:

function doSomething (callback) {
    var stream = createStream();
    stream.resume();
    stream.on('end', callback);
    stream.on('error', callback);
}

so, what if end fires, then error fires?

2: the same thing, what if nothing fires (remove stream.resume for example)? This obviously a bug in the function, but what you see is that everything just hangs.

4: you naively hook some asynchronous functions to emit error events from emitter, then when the error occurs, a listener tries to destroy emitter, causes another error event and ends up in an infinite loop.

5,6,7: each emitter without error listener can potentially crash your app. You have two options: try to understand where it is safe to omit one or add them explicitly everywhere.

8: debatable. TJ is a proponent of coroutines, so it's just his opinion.


Quoting from the next paragraph,

[...] you could think a routine is completely finished, until a library accidentally invokes a callback multiple times, or doesn’t properly clear handlers, and cause code to re-execute [...]

So it seems that Node.js is to blame only because you have to remember to invoke callbacks only once, and clean your handlers properly -- and some unspecified third-party developers fail to do so.





node.js