4 ms·
I don't think most code will be this dense with await.
by foota 10y ago
I don't think most code will be this dense with await.
- sidlls 10y agoAnd 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.
- piotrjurkiewicz 10y agoHe 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.
- imtringued 10y ago>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.
- steveklabnik 10y agoI 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.
- int_19h 10y agoI'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).
- foota 10y agoInteresting, 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.
- int_19h 10y agoDon'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.
- Sacho 10y agoIt 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).aspx https://msdn.microsoft.com/en-us/library/dd235635(v=vs.110)....