News for hackers. Stuff that matters.
Re:Some thoughts on asynchronous Python API design in a post... by foota on Sunday November 06, 2016 @10:47PM (#12888664)
I don't think most code will be this dense with await.
Re:Some thoughts on asynchronous Python API design in a post... by sidlls on Sunday November 06, 2016 @11:47PM (#12888879)
And Rust's developers think that 'unsafe' in third-party crates will be well-vetted and therefore actually "safe", most C developers don't think somebody will incorrectly free or screw with memory they've allocated and passed back to the caller, most C++ developers don't think anybody will (ab)use 'const_cast', and so on.

A lot of terrible bugs in code is caused by people making assumptions such as yours.

Re:Some thoughts on asynchronous Python API design in a post... by piotrjurkiewicz on Monday November 07, 2016 @12:22AM (#12888984)
He didn't make an 'assumption' like those ones you described.

This is an artificial example of a function copying unmodified data from source to destination. There are async and await tokens in every line, because every line is doing an IO operation. I a real world app this data would be somehow processed in between, using synchronous function calls, therefore without async/await tokens.

Re:Some thoughts on asynchronous Python API design in a post... by imtringued on Monday November 07, 2016 @02:59AM (#12889567)
>most C++ developers don't think anybody will (ab)use 'const_cast', and so on.

These constructs are opt-in. If you don't want them in your codebase you can find their location by a simple text based search and remove them. In C everything is "unsafe". You can't opt-out.

Re:Some thoughts on asynchronous Python API design in a post... by steveklabnik on Monday November 07, 2016 @02:13PM (#12893947)
I don't think anyone is saying that you'll never see crates with bad usage of unsafe. What you will hear them say is that by having the ability to share code, since more people are looking at and using the same codebase, it's more likely issues will be found, and that when they're fixed, they help everyone using the package, rather than just those who found it.
Re:Some thoughts on asynchronous Python API design in a post... by int_19h on Monday November 07, 2016 @02:50AM (#12889547)
I've been writing async/await code for the past 2.5 years, and no, it actually is typically this dense, if you count tokens (real identifiers are obviously longer, so it's not as bad character-wise, and awaits are not quite as prominent).
Re:Some thoughts on asynchronous Python API design in a post... by foota on Monday November 07, 2016 @03:10AM (#12889596)
Interesting, thanks for sharing that insight. Do you feel that your work is representative, or is there some reason that the code you write would have a higher than usual density? It seems like a lot of code, which is just business logic, would not use these constructs other than on the io barriers.
Re:Some thoughts on asynchronous Python API design in a post... by int_19h on Monday November 07, 2016 @04:55AM (#12889920)
Don't forget that async is "viral": if you call an async function and need to do something with its result, the calling function must in turn be async for await to work inside it. So the moment you start doing some async I/O at the bottom of some call stack, the entire stack becomes "infected" by async, and needs have awaits inserted in every frame.

And it so happens that I work on the kind of products where a lot of useful work revolves around I/O: IDEs.

Re:Some thoughts on asynchronous Python API design in a post... by Sacho on Monday November 07, 2016 @06:17AM (#12890235)
It doesn't have to be viral. C#'s tasks have a blocking Wait[0] method which allows you to use an asynchronous Task without changing the signature of your synchronous function. The tradeoff is more verbosity.

[0] - https://msdn.microsoft.com/en-us/library/dd235635(v=vs.110)....

Re:Some thoughts on asynchronous Python API design in a post... by int_19h on Monday November 07, 2016 @02:47PM (#12894329)
As noted in another comment, Wait is extremely prone to deadlocks - if you happen to Wait on a thread that's running the event loop, then no task that's scheduled on that loop can execute until Wait returns. So if you're waiting on such a task, or on a task that depends (no matter how indirectly) on such a task, you get a deadlock.

Now, if you're writing a library, you pretty much cannot assume anything about the event loop and what's scheduled on it. If your library invokes a callback at any point, all bets are off, because you don't know which tasks that callback may have scheduled, or which tasks it's waiting on. Similarly, if you provide a callback to a library, you also don't know which tasks you might block by waiting.

So, in effect, the only safe place to wait is on a background thread that was specifically spawned for that purpose, and that is guaranteed to have no event loop running on it.

Re:Some thoughts on asynchronous Python API design in a post... by nickkell on Monday November 07, 2016 @12:16PM (#12892764)
That's not the only tradeoff. It completely negates the benefit of asynchrony and can be a source of deadlocks