3 ms·
Could someone please explain what's Callback hell and why Toffee-script is doing to resolve it? The compiled JS code looks harder to read than using callbacks t
by Hengjie 13y ago
Could someone please explain what's Callback hell and why Toffee-script is doing to resolve it? The compiled JS code looks harder to read than using callbacks to me.
- jacobolus 13y ago“Callback hell” is when you need to do many asynchronous actions / call several asynchronous APIs with inputs to each call depending on the delayed results of some other call(s), and you are using callbacks to organize your control flow. Often you end up with either a large set of named functions being passed around as callbacks, or a deeply nested hierarchy of anonymous callbacks. Either way, control flow can be difficult to follow or reason about, both when reading the code and when debugging. Even simple tasks take large amounts of boilerplate code. The generated code is using callbacks. The point is that instead of writing something like (a cleaner, but still ugly, version of) the generated code on the right, you’d instead write the (quite easy to read) toffeescript code on the left. That said, I think coffeescript’s “it’s just javascript” slogan (and goal of generating readable code) is one of its most important features. It has to be quite a bit harder to debug than the coffeescript version, since the generated code has control flow that’s so different looking from the input.
- joeblau 13y agoWhat did you use to create the generated JavaScript? I'm still new to this and trying to figure out out.
- michaelmior 13y agotoffeescript is a language which has a compiler that generates Javascript.
- focusaurus 13y agohttp://callbackhell.com/ http://callbackhell.com/ That explains the many ways to structure your async code in pure JavaScript (no helper libraries or transpilers) so you don't create callback hell code.
- gaius 13y agoCallback hell is what you get when you take a language designed for doing at most client-side input validation, and try to write serious applications in it. As an analogy, consider what would happen if Outlook was written in VBA and you opened OUTLOOK.DOC in Word to read your email. Well that's GMail.
- gfxmonk 13y ago> The compiled JS code looks harder to read than using callbacks to me With good tools and a sufficiently correct compiler, that should be as irrelevant as worrying that compiled x86 assembly is harder to read than the C source.