5 ms·
> This is not a democracy. I agree 100%. But still, a lot of people are complaining about some of the Node.js API choices. They are complaining because it m
by camus 13y ago
> This is not a democracy.
I agree 100%. But still, a lot of people are complaining about some of the Node.js API choices.
They are complaining because it makes programming more difficult , and the truth is , async programming is hard when it relies on callbacks.
- hvs 13y agoWasn't that the original selling point of Node? That it used callbacks for async and that it was easier that way?
- wmf 13y agoNo, the original selling point was that Node forces all code to be async and Erlang is too weird.
- drderidder 13y agoNot the original point perhaps, but its come around to that. A couple years ago they settled on callbacks after a fairly active debate, as the least ambiguous option for continuation passing. As more people explore Node, callbacks are one level of abstraction too deep or just too tedious for some people. Fortunately there's a great selection of asynch modules to help them.
- AndyKelley 13y agoI really enjoy the callback paradigm. I love how powerful the abstraction of async code is. In procedural paradigm, there are some things that you want to accomplish that you simply cannot create an abstraction for, because the operation you want to do is time based. With the power of callbacks, you can abstract away complex things with a single function.
- jchrisa 13y agoI thought the original point was that it is JavaScript that can do stuff.
- _greim_ 13y agoAs AndyKelley mentions, the point was it being async and event-driven by default. JavaScript was chosen because it was the only language that was simultaneously popular and free of sync baggage.
- mahmud 13y agoThis became my all time favorite comment on HN. I have been laughing for a good 10 minutes.
- dragonwriter 13y agoThe main selling point of Node was that it was JavaScript, and since you are going to have to use that on the front-end anyway, you might was well use it on the backend. I've never seen anyone argue that callbacks are one of the easier ways of doing async.
- AndyKelley 13y agoNo, the main selling point is that it's an event-loop based paradigm where all the APIs are async by default. As opposed to python twisted or ruby eventmachine where you have to look for async versions of the libraries you want to use and people writing modules usually aren't even aware that you want to be event-based. So yes, grandparent is correct.
- marshray 13y agoSome people will buy into it for different reasons than others. This is a silly argument.
- arxpoetica 13y agoI've personally never had issues with the callback pattern. To the contrary, it forces me to have well-organized code, which is a ++.
- CyruzDraxs 13y agoIt was easier until we discovered even cleaner ways, and most of the Javascript community began to adopt them. But node chose to stick to the "old" ways. (Not really old, but not as shiny and new as the alternatives) I feel like promises don't need to be part of core though. It's easy enough to wrap the standard library in userland and just have other things depend on the wrappers.
- olegp 13y agoYou can use fibers. We are doing that via common-node (https://github.com/olegp/common-node/ https://github.com/olegp/common-node/) and are very happy with the choice at https://starthq.com https://starthq.com
- nadaviv 13y agoES6's generators and the `yield` keyword plays very nicely with callback-based code, doesn't require any changes to the underlying libraries and gives you a much nicer syntax to work with. See https://github.com/visionmedia/co https://github.com/visionmedia/co
- JoshGlazebrook 13y agoI've been looking at another library like the one you linked. Essentially the "yield" keyword can be compared to "await" in C#. https://github.com/bjouhier/galaxy https://github.com/bjouhier/galaxy
- 9999 13y agoA lot of short node.js code snippets you run into on the web use anonymous callbacks, and I agree, that gets ugly very quickly, but if you bind callbacks to methods on prototypes the code remains pretty readable.
- dclowd9901 13y agoI don't understand. Can you not just roll in a promises library (like Q)and call it a day?
- mattyod 13y agoWhy would you when someone already rolled a promises library like Q?
- dclowd9901 13y ago? Maybe I used the wrong lingo, but my intimation was that one use something like Q.
- driverdan 13y agoAs the post said, there are plenty of libs that add additional functionality in place of callbacks. Let everyone choose the way that works best for them.
- ilaksh 13y agoTake a look at ToffeeScript https://github.com/jiangmiao/toffee-script https://github.com/jiangmiao/toffee-script