Live data from Hacker News

Async/Await will make code simpler

blog.patricktriest.com

91–93 of 93 posts

Re: Async/Await will make code simpler

#91

I wish the await syntax was inverted; instead of waiting for an async function, let all async functions await by default. In other words, I wish this worked: let foo = myAsyncFunc() foo.bar() Why? Because that's the common case, and the caller shouldn't care whether the function is async or not. If you have a non-async function that you want to change to be async, or the other way around, then you have to change ever…

> If you have a non-async function that you want to change to be async, or the other way around, then you have to change every single call site.

At least in the direction non-async -> async, that is clearly a good thing, since you are changing semantics a lot.

This code is always safe:

    x = globalObject.a
    functionWithoutSideEffects()
    gobalObject.a = x + 1
While this is not:

    x = globalObject.a
    await functionWithoutSideEffects()
    gobalObject.a = x + 1
> It's way too easy to forget to add "await" to an async call, and doing so leads to failures that can be hard to track down.

This a situation that could clearly be improved with better detection of these cases. Or maybe it should be completely illegal to call an async function without a keyword, so you have to do either `await func()` or `promise func()`.

Re: Async/Await will make code simpler

#92
post #86
post #74

Earlier quoted context omitted.

In a cooperative multi-threaded model you can only have data-races at function-call boundaries. For example: `x+=1` can never data-race.

Except if your programming language allows you to override the += operator.

You are proposing a situation where someone overrides += to specifically both call a blocking function and to not make it work correctly. I'm not saying it doesn't happen, but bad code is bad code regardless of your paradigm.

Though I must admit I've not done cooperative multitasking in a language with operator overloading so I can't say whether or not this is a problem in practice.

Re: Async/Await will make code simpler

#93
post #92
post #86

Earlier quoted context omitted.

Except if your programming language allows you to override the += operator.

You are proposing a situation where someone overrides += to specifically both call a blocking function and to not make it work correctly. I'm not saying it doesn't happen, but bad code is bad code regardless of your paradigm. Though I must admit I've not done cooperative multitasking in a language with operator overloading so I can't say whether or not this is a problem in practice.

In can happen for example in Python with gevent.
Post reply on HN