DEV Community

Discussion on: Why I Don't Use Async Await

Collapse
 
gitkearney profile image
Kearney Taaffe

Whoa! such a well written article. I actually hate this new syntax. I blame all the java developers who are coming to node and not being able to understand promises

I was reading the comments, and your definition of "imperative" vs functional is correct.

# IMPERATIVE
let x = someFunc();
let y = anotherFunc(x);
return y;
Enter fullscreen mode Exit fullscreen mode

looks exactly like

# LOOKS IMPERATIVE
let x = await someFunc();
let y = await anotherFunc(x);
return y;
Enter fullscreen mode Exit fullscreen mode

with promises you are EXPLICITLY communicating to other devs that the value of x will be passed to another function y and that someFunc returns

# ER MUH GRR! mah value iz being pazzed to a funk-shun!
someFunc()
  .then(x => anotherFunc(x))
  .then(y => {'ok': true, err: null, result: y})
  .catch(err => {'ok': false, err, result: null})
Enter fullscreen mode Exit fullscreen mode

However, I feel like you missed the most important thing when using promises vs await...DEBUGGING!!! As of a few months ago, it wasn't possible to add breakpoints to await statements using chrome, but with promises, it was easy by literally

someFunc()
  .then(x => {
    anotherFunc(x);
  })
  .then(y => {'ok': true, err: null, result: y})
  .catch(err => {'ok': false, err, result: null})
Enter fullscreen mode Exit fullscreen mode

now, this brings me to another problem, devs printing stuff out instead of using breakpoints :SMH but, that's another rant. I wanted to say you're not in the minority of not liking async and await and it's imperative looking code