News for hackers. Stuff that matters.
Re:Interview with Ryan Dahl, Creator of Node.js by ralusek on Thursday August 31, 2017 @03:23PM (#15143076)
I should definitely make a macro at this point:

Callback paradigm has not been used in node development for 3-4 years at this point.

    return someHttpCall()
    .then(response => someOtherHttpCall(response))
    // Do 2 async operations in Parallel:
    .then(response => Promise.join(
      someCacheThing(response),
      someDBThing(response)
    ))
    .spread((cacheResponse, dbResponse) => sendBackToClient());
This isn't callback hell. Without creating or managing threads, I have established serial as well as an example of branched concurrent logic that is entirely nonblocking. Every promise is handled as a try catch, so error handling can be done at the end of the chain with a single `.catch`.

Clustered express application puts the performance well within what you would expect from Go/Phoenix, all of which are operating at an order of magnitude above Python/Ruby.

Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @04:03PM (#15143423)
I'm well aware of promises, thank you. I'm also well aware that there's very little difference in reality between a promise-based style of coding and a callback one. You still lose stack continuity, it's still much harder to chain operations that hop stacks, it's still a nightmare to debug compared to stack-based programming, etc.

If you've ever actually implemented a promise it's even easier to see how little promises actually get you. Given a callback-based API, it's absolutely trivial to wrap it in a Promise-based API. Fundamentally this is because promises give you very little in the end on top of callbacks beyond some syntactic sugar.

Re:Interview with Ryan Dahl, Creator of Node.js by ralusek on Thursday August 31, 2017 @04:38PM (#15143713)
First of all, I have absolutely implemented promises from scratch, and it IS trivial. However, "callback hell" is a reference to writing code with deeply nested callbacks, particularly with manual error handling at each level, both of which promises completely negate.

If you want to change the topic from "callback hell" to debugging across stacks, then we can do that. There was some work with "domains," since moved to AsyncListener/Continuation Local Storage to keep context across stack calls, but I don't disagree that improvements in this department are the place that NodeJS paradigm would currently benefit from most.

Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @05:00PM (#15143878)
It's still "callback hell" because you're still fundamentally writing code where you invoke an API and pass in a callback to handle the results. The fact that the callback you pass in happens to be a promise that allows you to stage other callbacks and/or promises doesn't really change things enough for the label "callback hell" to be inaccurate in my opinion.

A different programming paradigm, for instance, would be the use of delimited continuations such that the API you invoke suspends the current call stack, executes the I/O operation, then resume the call stack with the result of the I/O operation. Very few languages support that. One reason is that natively supported continuations in the programming language has far reaching consequences in terms of performance.

I'm not an expert on golang, but I believe this is essentially how goroutines are implemented: https://groups.google.com/forum/#!msg/golang-nuts/t3g8NbITYE...

Also keep in mind that I'm not 100% against callback-based programming. I have, for instance, implemented a non-blocking client for a custom TCP-based protocol using Netty. The client performed better than a blocking version that it was meant to replace. I played around with using Promises in conjunction with the library but ended up preferring callbacks to Promises for a number of reasons, some of which are specific to the JVM.

Re:Interview with Ryan Dahl, Creator of Node.js by Johnny_Brahms on Monday September 04, 2017 @02:02AM (#15166038)
> A different programming paradigm, for instance, would be the use of delimited continuations such that the API you invoke suspends the current call stack, executes the I/O operation, then resume the call stack with the result of the I/O operation.

guile has recently gotten guile-fibers which works like this. It is really an amazing way to do concurrency.

Re:Interview with Ryan Dahl, Creator of Node.js by dleslie on Thursday August 31, 2017 @09:17PM (#15145410)
Callback hell may as well be synonymous with stack incoherence. The hell arises from not knowing from whence you came.
Re:Interview with Ryan Dahl, Creator of Node.js by vilmosi on Thursday August 31, 2017 @05:10PM (#15143963)
>>> I'm also well aware that there's very little difference in reality between a promise-based style of coding and a callback one.

Then you're not using promises as they are intended to be used.

Re:Interview with Ryan Dahl, Creator of Node.js by mahyarm on Thursday August 31, 2017 @04:54PM (#15143834)
How do you get stack continuity in anything that is multithreaded unless the debugger adds special support for it?
Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @05:01PM (#15143885)
By programming using synchronous blocking code within a single thread, of course.
Re:Interview with Ryan Dahl, Creator of Node.js by ehsanu1 on Thursday August 31, 2017 @04:42PM (#15143753)
How about that await though.
Re:Interview with Ryan Dahl, Creator of Node.js by qooleot on Thursday August 31, 2017 @10:04PM (#15145579)
Promises made some very valuable improvements to code patterns relative to callback-based implementations, but as a broader "nodejs vs synchronous style code" its still much harder. You sound pretty versed, but other folks might struggle. Here is an example explanation:

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

If we're trying to show the simplicity of modern nodejs code with non-blocking I/O, I would suggest we lead with examples like:

const foo = await queryFooObject(id); await writeToFile(foo);

True, there's still plenty of value in promises, especially for things like:

await Promise.all(severalParallelQueries);