4 ms·
If you have callback hell in your code, it's not because the problem hasn't been solved, but simply that you didn't put the effort to npm install a simple libra
by weixiyen 15y ago
If you have callback hell in your code, it's not because the problem hasn't been solved, but simply that you didn't put the effort to npm install a simple library.
I agree that it is a problem if neglected, but most people don't allow it to be a problem in the first place.
It's like knocking on PHP because it could be used for templating and business logic on the same file. Just because you could, doesn't mean you have to (or should).
I honestly don't feel that it's as big of a problem as people make it out to be. It's simply a minor annoyance. The error handling is the killer.
- ZenPsycho 15y agoError handling isn't a problem if you understand MONADS
- weixiyen 15y agoCould you give a brief code example how monads eliminates the problem of error handling? Do you mean to put try catch in the monad around every async step it takes in? Just the API for how this would even look would be great.
- ZenPsycho 15y agothis is just a sketch to give you an idea of what I am talking about. right well you've probably used jquery before, so the api would look something like this. You start with a sequence of async actions you want to perform. $(ctx).geturl("http://example.com http://example.com).parseExample().renderTemplate().end(); Now this is a bit different from jQuery since all the methods here do is push method names and arguments onto a stack. it's the .end() method that reads in the stack and goes through and executes it. This means that each method along the way we've constructed a partial computation value- that is, the stack, which we can pass around as a value- just leave off the "end" method... var scrapeHN = $(ctx).geturl("http://example.com http://example.com).parseExample().renderTemplate(); now we can modify the computation by turning it into an error handling monad... var ecm = ErrorCatchingMonad(scrapeHN, errorCallback); this wraps each method in the monad with a try catch block, and calls the callback if an error gets thrown, and stops the chain from getting executed further. in fact this is how the origial monad was created var $ = DeferringMonad(scrapingAPI); which takes a normal jquery style plugin interface/chaining api and turns it into that deferring stack type api with an end(); method.
- telent 15y agoFor "could be used for", read "was designed for".