top | item 16735764

(no title)

namelost | 8 years ago

Anybody who has used node.js for more than 10 minutes knows that the callback style makes code completely unreadable. Unreadable code is a breeding ground for bugs.

Back in 2009, that was an acceptable trade-off, because there were advantages to JavaScript, such as sharing code between client and server.

Now we have promises and we don't have to put up with callbacks anymore (eventually!). FWIW async/await is the syntax, and promises are the runtime, they are not competing features.

discuss

order

erikpukinskis|8 years ago

That’s a really insulting way to argue your point. I’ve been writing JavaScript for 15 years. Full time for probably six years, when I dropped Rails for Node and Ember.

Right now I am programming full time in a promise shop for work, so I am very familiar with that. At home I write 100% callback style and find it superior.

The worst is when you have to mix the two, which is why NPM is such a shit show, and why I think async/await will only make things worse.

If you’re willing to spend a few minutes considering an alternative perspective to your own, you might read this: http://callbackhell.com

You say promises are more readable. I do agree promises make it easier to read and write awful code with gnarled architectures. Callbacks force you to name things and separate concerns, which is helpful if your goal is to write good code. If you just want to hack layer upon layer of garbage into the system, as most employers would prefer you do, then promises will help you hold on for that ride longer. Callbacks will break down faster.

I think that’s a feature, as it alerts me to architecture problems sooner. But you may prefer less refactoring and a more additive-only programming model, in which case promises will be a useful tool for you.

namelost|8 years ago

If your coworkers are so bad, wouldn't you rather get a nice message in your console when they forget to handle an error? With callbacks, error handling is entirely on the honor system.

There may well be some situations where callbacks are tolerable, but any time you have to converse with an external synchronous resource like a filesystem, database or REST API, it's just painful. Making a new function (named or otherwise) for each line of code is not good style, in any language.