Hacker News new | ask | show | jobs
by raarts 3700 days ago
When I initially encountered event -based processing (libevent in C), those callbacks were indeed difficult to wrap my mind around. But I learned to structure the code in the editor, keeping everything together which made it manageable. I 've worked with node for a couple of months now, and I find promises to be more confusing, because it obfuscates the callback in my mind, and makes it look like ordinary function calls.
2 comments

The advantage of promises is that you can return them as a type, you can't do that with a callback. If you fetch something from a database , your data access object can return a promise and let the client code deal with the result. Promises are composable by nature, callbacks are not.
I can see how it can be hard to follow returns sometimes but if the promises are used well, it reads and flows really nicely.

Here's a good article on promises that helped me, especially since I had seen a lot of misuse in JS land before I started using them:

https://pouchdb.com/2015/05/18/we-have-a-problem-with-promis...