> And I really worried about the fact that many people here dislike callbacks in Node.
I think that may be a misrepresentation of the general sentiment (although I can only speak for myself). I'm a fan of callbacks, but I'm also a fan of easily maintainable code. Callbacks are extremely easy to write, and in some cases you can make the case that they're *too* easy to write (and hence we end up with 7-level "pyramids" that are a nuisance to refactor after-the-fact). Just to be clear, I'm not saying that callbacks aren't too blame for poorly structured code... but they do lend themselves quite nicely to it. > I love callbacks in node. They reflects how machine executes the code. That seems like a bit of a stretch. True, callbacks do represent a consistent indicator that "something async probably happens here", but many other abstractions can serve that purpose as well. > I don't understand why people say that callbacks are not composable. Without the assistance of some utility, callbacks do not combine very elegantly. The fact that you can't run X callbacks in parallel and then resume without some sort of state tracker is one indicator of this. Even something as simple as logic branching with callbacks gets cumbersome. And I say this as someone who still goes vanilla callbacks 99% of the time (over, e.g., Promises). Callbacks are easy to reason about, and combined with something like async (the library), they're easy enough to manage as well... but even I have to give a hat tip to Promises when it comes to actually being composable. > Adding generators to node, IMO, is just trying to make node as lame as other lame languages (C#, Python, Ruby, Java... this list never ends). Generators are already spec'd in ES6, so Node gets them by virtue of the fact that they're in the language (and implemented in V8). No one is making generators as a custom add-on to Node. At the end of the day it all comes back to abstractions and the different semantics around them. In my own experience, overly nested callbacks gets to be a pain, but I find it even more of a pain to deal with named functions where the logic is split up all over the file(s). Generators hit a nice sweet spot for being amply clear about the async semantics (just like callbacks), but without requiring the cognitive overhead of N-level deep callback nesting. On Monday, August 12, 2013 3:46:44 AM UTC-4, Chaoran Yang wrote: > > I've read everyone's post up to this point in this thread. And I really > worried about the fact that many people here dislike callbacks in Node. > > Before I came to node world, I used C#, Java, Python, Ruby to write code > running on server. And I don't like them. Why? because they are > synchronous. They make an app that is asynchronous in nature (IMO most web > apps are asynchronous, if not all of them) looks synchronous in code. Why > this is bad? Because when programmer write code looks synchronous, they > tend to think that the code executes synchronously. This unintentionally > encourage programmer to write code that looks good but performs really bad. > > Let's be realistic. I'm a compiler guy. I write compilers as part of my > PhD. I can assure you that compilers are not that smart to optimize away > the layers of abstraction you built to write your fancy looking code. I'm > not going to sacrifice performance just for prettier code. People may say > that prettier code are more reusable and maintainable. But I think that's a > big lie. Reusable code are about algorithms, patterns, interfaces. Use > generators or callbacks makes no difference in either of these three at all. > > I love callbacks in node. They reflects how machine executes the code. I > don't use any control flow libraries (I built some small control-flow > utilities though; they are just tens of LOC, but powerful enough). I find > the callbacks and event emitters very intuitive. I can even visualize how > the code executes in my head by just reading the code. This means I can > immediately get a sense of how the code performs, whether the algorithm it > used is good or bad, by simply reading it. This is a huge advantage. I can > use none of other server-side languages to achieve this. > > I don't understand why people say that callbacks are not composable. They > are absolutely composable if you use them correctly! Callbacks + good > programming practice is enough to solve every program correctly and, more > importantly, efficiently. Adding generators to node, IMO, is just trying to > make node as lame as other lame languages (C#, Python, Ruby, Java... this > list never ends). > > On Monday, August 5, 2013 10:23:11 AM UTC-5, Christopher Probst wrote: >> >> Hi guys, >> >> today I read something about the upcomming es6 generator support and how >> useful they are in combination with promises (Q library for instance). >> >> The problem with node is that it provides only asynchronous functions >> (and synchronous.. pff). >> I think in order to use promised based io the node.js should support an >> additional function for each asynchronous function in the future or maybe a >> library which does this. >> >> I know that the Q library already exports functions like "Q.denodeify" so >> it's definitely not much work but it's still work. >> >> I've started with node a year ago and it is really a nice tool but I >> always hated the callbacks. They are not composable, verbose and absolutely >> ugly. >> >> What do you think about this issue ? Any chance direct support for this >> will ever be added ? >> >> Regards, >> Chris >> > -- -- Job Board: http://jobs.nodejs.org/ Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines You received this message because you are subscribed to the Google Groups "nodejs" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nodejs?hl=en?hl=en --- You received this message because you are subscribed to the Google Groups "nodejs" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/groups/opt_out.
