r/javascript • u/wheatBread • Nov 02 '12
Escape from Callback Hell
http://elm-lang.org/learn/Escape-from-Callback-Hell.elm
5
Upvotes
4
1
Nov 02 '12
Signals sound very similar to custom events to me. Sure there's a little cruft when you do it in javascript, but it still solves the major program of an unreadable code structure.
3
u/[deleted] Nov 02 '12
As the author himself admitted, continuation passing style is similar to how assembly languages work, and we've built constructs on top of that to make it easier to read.
But unlike assembly languages, Javascript is very mutable, almost to its very core, so you don't need another language to solve this problem. There are a few libraries to solve this issue, such as async, promises/when, and my own solution queue-flow.
Callbacks don't need to be written as nested anonymous closures, that's just the first reaction a user has because they're writing their code linearly with respect to their code's execution. These libraries let you structure your code in a similar linear fashion, but without the nesting, so code reuse becomes more feasible and readability remains high while not blocking the CPU.