News for hackers. Stuff that matters.
Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @02:59PM (#15142834)
Node.js brings callback hell to the serverside world of threads and we're supposed to be grateful? It's like you don't know the history of computing. Callback-based code was the original programming model in UNIX dating back decades! Threaded code came about because it's far easier to write it than callback-based code.

The ONLY reason to do callback-based code is for performance reasons: for network-IO-heavy apps there is less OS-level overhead from managing thousands of connections with a few threads using the OS-provided non-blocking I/O operations than managing a connection per thread. Even then, if you actually want to do better than connection-per-thread, you have to avoid the POSIX API for non-blocking I/O and use whatever OS-specific API is available for better performance (epoll, kqueue, or completion ports).

The greatest joke of all though is that Node.js is dirt slow because Javascript is dirt-slow. Yes, you may be able to invent some microbenchmark where Node.js looks good, but the only reason it does in that benchmark is because the Node.js app is spending 99.9% of it's time executing code in a C library. Any real-world Node.js app is going to be slow because Javascript in general, even on V8, is anywhere from 10-100x slower than C or even well-written Java.

And worst of all, Node.js is single-threaded! If you want to scale onto all your cores you have to go multi-process, which is an incredible pain in the general case. So, you switch to a runtime and framework that forces a more difficult way of programming on you (callback hell) but which is better for general networking performance, but you use a dirt-slow, single-threaded runtime while doing so. You are basically ending up with the worst of both worlds, and any decent development team will run circles around you in performance and productivity with just about any other backend stack.

Re:Interview with Ryan Dahl, Creator of Node.js by disordinary on Thursday August 31, 2017 @05:59PM (#15144320)
V8 is not dirt slow. You may dismiss benchmarks where Node looks good as "invented" but there are countless real world examples of people moving from other languages to node and experiencing a huge speed increase.

I know of one startup that had a fortune 500 company sign up to their service and their dotnet APIs couldn't hold the load and the cost of scaling them wasn't sustainable. They rewrote the hardest hit APIs in node over a weekend and were shocked at the improvements. I also know another startup that had a similar experience, they moved off of Ruby to node and were shocked at the speed increase that they were getting. They couldn't be competitive with their competition with their old codebase.

Despite what I just said above speed isn't necessarily the most important factor. Infrastructure is cheap and developers are expensive. If I'm asked what the best programing language or platform is my answer is usually the language and platform that your team is most productive with. Only a few companies get successful enough that speed is the deciding factor in platform choice, if we say that productivity is the most important factor then the JS/Node combination is right up there as one of the more understood and productive systems.

Re:Interview with Ryan Dahl, Creator of Node.js by jonnycoder on Friday September 01, 2017 @01:34AM (#15146370)
You are spot on as I have been developing in node for the past 2 months. Coming from doing python and c# in the past, I picked up the asynchronous nature + promises and their "gotchas" within a few days of writing and rewriting an activemq module. All of our other requirements/stories have been developed at such a high speed relative to my past projects. Combined with docker and a QA team that writes automated tests with postman and protractor, our continuous integration is at a high maturity level.
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);

Re:Interview with Ryan Dahl, Creator of Node.js by brondeau on Thursday August 31, 2017 @03:34PM (#15143177)
As with any tool, there is a right and wrong way/time to use it. Node.js would not be the monster success and influencer it is today if it was the 'worst of both worlds'. For example, using a single threaded environment can solve so many issues that are present in a multi-threaded environment, such as reducing possibility of race conditions (though you can still write crappy single threaded code that introduces race conditions). When used in the right way, it can be and is best of class. In other instances, it is a boat anchor. Just my 2 cents
Re:Interview with Ryan Dahl, Creator of Node.js by WA on Thursday August 31, 2017 @03:12PM (#15142941)
So if I don't like Java and C, what's your suggestion I should use instead to get the best of both worlds and not the worst?
Re:Interview with Ryan Dahl, Creator of Node.js by jswizzy on Thursday August 31, 2017 @05:56PM (#15144304)
Any language that uses the actor model for concurrency which is basically every language created in the last decade. Elixir, GO, Akka framework for Java and C#, Pony, Dart, Erlang, ELM, SCALA, ...
Re:Interview with Ryan Dahl, Creator of Node.js by bonesss on Friday September 01, 2017 @05:49AM (#15147220)
F# with it's built in actor model, robust OCaml based syntax, great support for functional Akka[.net] actors, simplified concurrency and asynch programming support, and very own ELM implementation is a great contextual answer for anyone who wants to be on the front lines of lightweight non-blocking concurrent & parallel web development in .Net land.
Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @04:07PM (#15143457)
C# is fairly efficient while still having managed memory. And, of course, golang was designed to hit the sweet spot of automatic memory management, decent performance, and non-blocking I/O.

Beyond that, there's things like Erlang and Elixer, which I am less familiar with. My understanding is that the Erlang VM is significantly slower than JVM or CLR implementations but generally faster than scripting language runtimes.

Re:Interview with Ryan Dahl, Creator of Node.js by lackbeard on Friday September 01, 2017 @02:04AM (#15146489)
Go, Erlang, Elixer, Haskell, Clojure, Scala.
[dead]
Re:Interview with Ryan Dahl, Creator of Node.js by sreque on Thursday August 31, 2017 @04:05PM (#15143443)
I have written servers in C with epoll that were used in production, thank you. And yes, I'm aware of async/await and its limitations. State-machine-style transformations from blocking-looking code to non-blocking code are definitely helpful, but in the end still fall short in terms of usability to a full blocking style of programming.

To even begin to approach the ease-of-use of blocking-style programming you need something akin to delimited continuations in your programming language.