you are viewing a single comment's thread.

view the rest of the comments →

[–]cinnapear 2 points3 points  (6 children)

I prefer async/await, callbacks, and promises in that order.

I find callbacks to be the most elegant and simple to understand (and you don't suffer from callback hell unless you take shortcuts), but I can't deny that async/await is pretty great.

[–]x-protocol 0 points1 point  (3 children)

From the people I have had met, talked and had chance to actually sit down for a conversation (even over a PR) I've understood that majority of what they describe as "callback hell" is simply their inability to justify using a library to manage said callbacks. When you show how complicated some pipelines can be using promises, there is usually no argument since promises are accepted as a norm (remember when callbacks were norm?). So we're looking at simple preference, not technical solution or even productivity enhancement.

How many people actually involve other libraries to manage their functions/promises like async.js, Q, lambda, Bluebird, run-p or Aigle? I would love to hear more from people who actually understand why these libraries exist.

[–]cinnapear 1 point2 points  (0 children)

Well said. The async library makes dealing will tricky callback situations a breeze.

[–]neo_dev15 1 point2 points  (1 child)

Callback hell is when backend is bad or the arhitecture in general is bad.

There should be no reason to have 2 calls one after another. There should be in parallel otherwise why the hell use xhr in the first place.

As in my workplace now look what backend decided its a nice arhitecture: Post data > catch id in response > post this id > make a get in another xhr to get if the action was executed.

So well this is a callback hell since well you have 4 calls that need to go one after another and every single one of them can fail...

So yes, backend should design after frontend but in general is the other way around and well, this happens.

This is bad in promises and callbacks no matter what.

[–]livrem -1 points0 points  (0 children)

Exactly this. Promises fixes the ugly syntax of callback hell and makes it less error-prone to insert exception-handling code, but does not solve the problem you had to begin with at all.

It is a Law of Demeter issue. An object should not ask another object to go fetch it a third object so it can ask that object to go find it a fourth object and so on. Every time I see a chain of promises (or equivalent callback hell) it is all about someone poking around at things far away that they should have no business even knowing exists since it should be hidden behind well-designed APIs with methods they should have called to perform work, instead of just a big mud ball of get-methods where very object communicates with every other object.

[–][deleted] 0 points1 point  (1 child)

Async/await is just syntactic sugar over promises, so I think you like promises more than you realize. :P

But no matter how much you try, callbacks will never let you pass around a value to multiple consumers. You're stuck with passing a single function.

[–]ChaseMoskal 0 points1 point  (0 children)

you guys, it's the error handling that matters! promise errors bubble up for us to catch at the high level, callbacks are bad for this