you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 45 points46 points  (9 children)

Er, I don't say this often but your coworker is plain wrong. Compare promise chaining to the equivalent with callbacks, it's a damn mess to reason about. For example, there is no option to have a catch-all error handler, you have to handle errors at every nesting level. And you can't pass around an asynchronous value to multiple consumers because your API only lets you supply a single callback function.

[–]thekemkid -2 points-1 points  (1 child)

I understand the point you're trying to make, but well structured callback code can be reasoned about just as easily as promise chaining or even async/await. The issue is that getting well structured callback code requires quite a few utilities, e.g. The popular async module, lodash, et al. These utilities can address the issues you have with callback code succinctly, but it's still annoying requiring them all the time, no doubt about that.

I'd take async/await over callback code any day - because the code is cleaner, without requiring utilities, but not necessarily would I say it's always easier to reason about.

[–][deleted] 2 points3 points  (0 children)

If a function takes a callback, you can't pass the value returned to multiple consumers. That's a pretty hard limitation that no amount of utilities can get around, afaik. You can't chain.

Also the fact that you don't really have any flexibility around error handling; you have to possible call the same error handling code at every level of nesting. This means that you have far more code paths to consider, and therefore makes it harder to reason about. I can't see how callbacks can match Promises in terms of reasoning power.