Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Promises add complexity? #67

Open
dmitriz opened this issue Jan 16, 2016 · 5 comments
Open

Promises add complexity? #67

dmitriz opened this issue Jan 16, 2016 · 5 comments

Comments

@dmitriz
Copy link

dmitriz commented Jan 16, 2016

This is the first time ever I read that promises "add complexity over callbacks". Every single other post states the opposite:

fs.readFile('movie.mp4')
  .then(function(data) {
    // do stuff with data
  })
  .error(function(error) {
    // handle error
  })

This adds complexity, and not everyone wants that. Instead of two separate functions node just uses a single callback function. Here are the rules:

@tytskyi
Copy link

tytskyi commented Feb 25, 2016

@dmitriz i guess it adds complexity for newbies. When i started to work i used callbacks from the beginning, but i got Promises only after 2 years of working.

@abdulhannanali
Copy link

@dmitriz Callbacks are certainly an easier way of understanding the asynchronous flow. Newbies should start with callbacks. After some time, you get hands on promises very naturally.

@zeke
Copy link
Contributor

zeke commented Feb 29, 2016

@dmitriz here's an interesting update on the state of promises in core node: https://medium.com/@isntitvacant/adding-promise-support-to-core-a4ea895ccbda#.3nl0mjvrn

@vitaly-t
Copy link

vitaly-t commented Aug 1, 2016

A great example of this is node's use of callbacks. Early on node experimented with a feature called 'promises' that added a number of features to make async code appear more linear. It was taken out of node core for a few reasons:

  • they are more complex than callbacks
  • they can be implemented in userland (distributed on npm as third party modules)

Whoever wrote this, cannot be taken seriously.

If promises are considered more complicated for beginners, then it should be stated accordingly. Otherwise, it only creates confusion - the beginners read this and take it absolutely, to never look at promises again. Bad-bad teaching.

The correct statement is along these lines: Promises offer the best approach to asynchronous programming, though they do require additional learning. (just like everything that is worthwhile)

@ralphtheninja
Copy link

ralphtheninja commented Aug 1, 2016

A correct statement would explain the differences and trade offs you make without any bias. Nothing can be better in all ways. You always make a trade off. In this case more code (in trade off with gaining a better/different/simpler api) and therefore more complexity.

Some people might find promises easy to grasp and some might require additional learning and vise versa with callbacks. In the node case I prefer teaching how to use callbacks first and then explain what promises can give you on top, i.e. what you gain (or lose) by using them.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants