I've seen a fair amount of callback bashing on Hacker News recently.
Among the many proposed solutions, one of them strikes me as particularly clean: "asynchronous wait" or "wait and defer". iced-coffee-script had this a while ago. Kal just debuted with an identical solution, only differing in syntax. Supposedly LiveScript supports this with "backcalls".
I must say, "asynchronous wait" or "monads" - whatever you want to call it - seems like an improvement over callbacks. But I'm here to say that actually... callbacks are pretty okay. Further, given how clean callbacks can be, the downsides of using a compile-to-js language often outweigh the benefits.
I have 2 rules of thumb for code organization which makes clean callback based async code brainless:
- Avoid nontrivial anonymous functions.
- Put all function declarations after the code that actually does things.
Your new post is loading...