Live data from Hacker News

Node v7.5.0 Released

github.com

121–130 of 142 posts

Re: Node v7.5.0 Released

#121
post #70

Earlier quoted context omitted.

http://callbackhell.com/ I think the mental gymnastics needed to write non blocking code also makes you understand the flow of your program, witch allows good abstractions. After a while it becomes a second nature and you get a mental picture of all branches. Thinking about code as events (button.onclick = showPicture), makes you a better programmer, as this is how a computer work. And when your program has to scale…

Yes! Callback hell is a gift that forces you to refactor code until it's easy to understand and your abstractions are correct. Promises are a band-aid that gives you shallower indentation, and then simply hides the callback complexity in invisible objects that are even harder to debug. The problem is the modern web development world is all about creating two classes of programmer: framework programmers who control th…

    > Callback hell is a gift that forces you to
    > refactor code until it's easy to understand
That doesn't sound like a gift to me. Unless you meant they are so painful as an abstraction that they gifted us with promises and then async/await.

Almost everyone here has worked with callbacks and you'll be hard-pressed to find people that felt like they improved the code base.

Just tiny changes to the logic, like an if-statement with branching async behavior, would cause disproportionally large changes in the callback structure, pretty much touching every line/indentation.

The rest of your post is really negative and judgmental. Not sure why you felt it was necessary.

Re: Node v7.5.0 Released

#122
post #112
post #110

Earlier quoted context omitted.

The huuge difference once you understand its implications is that you can: return function().then(() => ...).then(() => ...) ...and the caller of you function can decide to chain even more stuff after, in the simplest case. Most obvious benefits, though not the biggest, is that you simply can return a promise ad drop the ugly extra callback argument that you function needs to have. For example: function foo(cb) { asy…

As I said: promises return values. That's great. But describing callbacks as "worst coding style ever" and "intellectual lazyness" is hyperbole to describe a style that most of the JS community uses. Also: not sure if you mean 'you' singular or 'you' plural, but personally I use a combination of callbacks for node stuff with basic async patterns applied (not the 'async' module) and promises.

The hyperbole is not my style actually, but I use it when talking about JS because I've came to realize the in the JS community it's the only way to be heard.

Generally I see the JS async styles continuum as: (0) callbacks skipping the intermediate steps in this continuum, (1) and (3) because they can lead to either badly composable code or subtle bugs. Also, I stressed the "intellectual lazyness" label because I know lots of people learn async module and this, "ok, this is good enough, I'll stop learning new things about writing better async code in JS".

...and I'm ok with good ol' callbacks where it makes sense for performance reasons, like core part of web frameworks or game engines (even if there is no sensible speed reduction, there is a memory overhead from creating a zillion promises).

Re: Node v7.5.0 Released

#123

Earlier quoted context omitted.

Yes! Callback hell is a gift that forces you to refactor code until it's easy to understand and your abstractions are correct. Promises are a band-aid that gives you shallower indentation, and then simply hides the callback complexity in invisible objects that are even harder to debug. The problem is the modern web development world is all about creating two classes of programmer: framework programmers who control th…

> Callback hell is a gift that forces you to > refactor code until it's easy to understand That doesn't sound like a gift to me. Unless you meant they are so painful as an abstraction that they gifted us with promises and then async/await. Almost everyone here has worked with callbacks and you'll be hard-pressed to find people that felt like they improved the code base. Just tiny changes to the logic, like an if-stat…

Oh, sorry... in editing I forgot the bit about where promises fit in the framework/app paradigm. Added a paragraph.

Re: Node v7.5.0 Released

#124

Earlier quoted context omitted.

You have a number of ways of keeping a handle on async code now. 1. Native ES6 promises will cover most of your basic needs. See https://developer.mozilla.org/en/docs/Web/JavaScript/Referen... . In fact, unless you have very specific needs not covered by native promises, you shouldn't drop a third party library into your project. 2. For more advanced operations on promises, use Bluebird. See http://bluebirdjs.com and…

Promises don't cover a lot of scenarios in async usage. When building some node apps, especially toolage, doing everything async just isn't possible, or is a lot more work for little benefit. The second you use a promise, anywhere, working with its output is now also async, you cannot 'wait' for it. I don't know if async/await actually does this or not, but until that functionality exists in JS, working with node, fo…

>working with its output is now also async, you cannot 'wait' for it ... , but until that functionality exists in JS, working with node, for me, is a pile of junk code, especially when libraries force you to use them asynchronously

Asynchronicity is something that Node makes explicit and necessary for I/O, and it's practically a core principle of Node and javascript. If you try to avoid asynchronicity entirely, then you're not going to get much further than you would if you tried to avoid classes in Java.

Async/await is a very useful syntax sugar to working with promises, but it's not built to let you ignore asynchronicity entirely.

Re: Node v7.5.0 Released

#125
post #80

Earlier quoted context omitted.

My understanding was that Node didn't support native ES6, is that no longer the case? Or are you talking about using a transpiler?

You can always check here: http://node.green

I don't see ES6 modules (import/export keywords etc) in that list. Where is that feature hiding?

Re: Node v7.5.0 Released

#126
post #48
post #44

Earlier quoted context omitted.

Promises have been native in node for awhile, so any time you spend in callback hell is entirely your prerogative.

Wrapping every standard library method with my own promises sounds like just another flavour of hell, and it still doesn't address the fact that the standard library is callback hell.

promise-ring is one library that does the wrapping automatically from node-style callbacks to promises. I think Bluebird also has an auto-wrapper.

Re: Node v7.5.0 Released

#127

Earlier quoted context omitted.

You have a number of ways of keeping a handle on async code now. 1. Native ES6 promises will cover most of your basic needs. See https://developer.mozilla.org/en/docs/Web/JavaScript/Referen... . In fact, unless you have very specific needs not covered by native promises, you shouldn't drop a third party library into your project. 2. For more advanced operations on promises, use Bluebird. See http://bluebirdjs.com and…

Also highly recommend the npm async library[1] even though the hipster way is now native async/wait or promises. caolan/async has some amazing sugar on nearly every use-case the most common for me being async.auto(). [1] https://github.com/caolan/async

The "hipster" way? Do they wear a silly hat and have little-to-no pant break?

Re: Node v7.5.0 Released

#128
Just wanted to leave a comment about the ChangeLog which is a list of commits. It would be nice if they sat down for a day (or two) to write down proper release notes that made reference to various commits and outlined exactly what is changing, like if there are backwards compatibility issues or if there are very important bugs solved.

The changelog here looks like a git log :/ I mean, I can do better on my own projects (and have been trying to do so with node-oauth-libre) but for a major project it would be nicer if it had nice release notes.

Re: Node v7.5.0 Released

#129
post #115

Earlier quoted context omitted.

IMO promises and Bluebird made `async` obsolete.

They certainly did not, if for nothing other than `async.auto()`, which automatically runs a dependency graph of async functions.

A Promise/async/await implementation of 'async.auto' is trivial, as you can use the behavior of promises themselves to avoid solving the graph:

  async function Promise_auto(tasks) {
      const keys = Object.keys(tasks);
      const results = { };
      const taskPromises = { };
      function runTask(key) {
          if (!taskPromises[key]) {
              taskPromises[key] = (async () => {
                  let fn = tasks[key];
                  if (fn instanceof Array) {
                      const deps = fn.slice(0, -1);
                      fn = fn.slice(-1)[0];
                      await Promise.all(deps.map(runTask));
                  }
                  results[key] = await fn(results);
              })();
          }
          return taskPromises[key];
      }
      await Promise.all(keys.map(runTask));
      return results;
  }
Usage example (terms intentionally out of order):

  (async () => {
      const start = new Date();
      const results = await Promise_auto({
          write_file: ['get_data', 'make_folder', async (results) => {
              console.log('in write_file', results);
              await Promise.delay(1000);
              return 'filename';
          }],
          email_link: ['write_file', async (results) => {
              console.log('in email_link', results);
              await Promise.delay(1000);
              return {file: results.write_file, email: 'user@example.com'};
          }],
          get_data: async () => {
              console.log('in get_data');
              await Promise.delay(1000);
              return [ 'data', 'converted to array' ];
          },
          make_folder: async () => {
              console.log('in make_folder');
              await Promise.delay(900);
              return 'folder';
          },
      });
      console.log('results = ', results);
      console.log(`It took ${(new Date() - start) / 1000} seconds`);
  })();

Re: Node v7.5.0 Released

#130
post #128

Just wanted to leave a comment about the ChangeLog which is a list of commits. It would be nice if they sat down for a day (or two) to write down proper release notes that made reference to various commits and outlined exactly what is changing, like if there are backwards compatibility issues or if there are very important bugs solved. The changelog here looks like a git log :/ I mean, I can do better on my own proje…

...even if they only did this for the top 20/50/100 changes, it would be well worth it.
Post reply on HN