Lurker News

Comments (110) 18 threads

Show all comments

Showing thread 13 of 18

scottmf2 replies#
Looks great. I love modern JS, and the faster everyone can move on, the better!

I didn't see any async/await stuff though, is there a reason for that? I'd imagine it would make some code much easier to follow.

_pmf_2 replies#
> and the faster everyone can move on, the better!

Why? Where does this mindset come from?

nailer#
Direct style is easier to reason about. Control passes onto the next line consistently, for both async and sync operations.

Do you really prefer callbacks or just use them because they were once necessary? Are they so good you'd use them for sync operations too?

   add(a, b, function(sum){
     ....
   })
Personally: that seems like a waste of time. I'd rather just do:

  var sum = a + b;
Likewise I'd rather do:

  var response = await superagent.get('https://...')
scottmf#
Why would you want to use callbacks?

Here's a code example from an npm package I was looking at, vs how I would rewrite it in modern JS:
https://gist.github.com/scf4/8157abd755eb9c232e87dcc342b78b4...
Some of it may be preference but a lot of it is objectively simpler to reason about.
I don't understand why anyone would choose to make things unnecessarily complex.

fanpuns#
If OP wrote using ES2015 then it wouldn't be included, async is defined in 2017