News for hackers. Stuff that matters.
Re:Python Asyncio: The Complete Guide by throwawaymaths on Thursday November 10, 2022 @10:53AM (#33548241)
> Async just makes that simpler to read and write.

Really? I definitely had a huge struggle reading async python, because generators and yields break the concept of "what is a function" and struggled writing async python because of function coloring.

Re:Python Asyncio: The Complete Guide by andrewstuart on Thursday November 10, 2022 @11:38AM (#33549087)
Day to day Python async should be using generators and yields.
Re:Python Asyncio: The Complete Guide by nine_k on Thursday November 10, 2022 @11:46AM (#33549228)
Generators are great for predictable concurrency. Things like asynchronous I/O, with timeouts and stuff, require more support on the language and stdlib level.
Re:Python Asyncio: The Complete Guide by dekhn on Thursday November 10, 2022 @02:12PM (#33551530)
I am really not a fan of generators and yields for the same reason. But over time I've come to see it as ever-so-slightly more elegant syntax sugar for a class that maintains internal state to sequentially return specific values in response to a series of calls to a function.
Re:Python Asyncio: The Complete Guide by throwawaymaths on Thursday November 10, 2022 @02:25PM (#33551712)
The least they could have done is sugared it to something that isn't "def", like "gen" or "defgen"
Re:Python Asyncio: The Complete Guide by jborean93 on Thursday November 10, 2022 @03:18PM (#33552648)
Unless I'm misunderstanding your comment they do, it's `async def` to denote a coroutine.
Re:Python Asyncio: The Complete Guide by dekhn on Thursday November 10, 2022 @04:09PM (#33553406)
They're referring to generator functions. They typically open a resource and then use a for load to read (for example) a line at a time and yield it. once you yield, control returns to the caller (like a return) but subsequent calls to next on the returned expression pick back up at the yield point. So function calls maintain state-behind-the-scenes. It's not just a simple call-and-return model anymore.

To me this violates a core principle: the principle of least surprise. It completely changes how I have to reason about function execution, especially if there are conditionals and different yields.

Re:Python Asyncio: The Complete Guide by nicwolff on Thursday November 10, 2022 @05:11PM (#33554230)
It's the buried `yield` in a loop somewhere, magically changing your function into a generator, that can be confusing – it's on the original coder to have the docstring say `"""Generator yielding records from DB."""` or something.