4 ms·
Most examples of callback hell on blogs and forum comments are just linear pyramids where each callback neatly waterfalls into the next. They are manageable but
by danneu 10y ago
Most examples of callback hell on blogs and forum comments are just linear pyramids where each callback neatly waterfalls into the next. They are manageable but ugly which I think is why it's common to dismiss promises/await as cosmetic.
In practice, callbacks become a problem when you need conditional async logic. Like if you have your simple callback pyramid but want to fork the chain at some level and merge it back at the end.
What would've been a basic if-condition with promises/await is often an invasive change with callbacks where your only tool is to extract and rewrite logic into helper functions. A simple conceptual change easily blossoms into heavy indirection where taming the complexity becomes an engineering feat.
At the end of the day, we all have different appetites for trade-offs.
- mkozlows 10y agoThat's definitely a better example, yeah. I think that it's a very manageable problem -- if your functions are small and compositional in the first place, you're not going to be refactoring your 100-line magnum opus in a major way when you introduce a new conditional bit -- but that's definitely at least a problem that rings true to me in the way that so many "callback hell" complaints don't.