News for hackers. Stuff that matters.
Re:Python 3.11: “Zero cost” exception handling by dragonwriter on Wednesday October 06, 2021 @02:14PM (#28776315)
> Why not just use a normal loop and check a return value from the iterator?

Because an iterator needs to be able to return any python value, and if you did that, there would be at least one python value that an iterator could not actually return.

Unless you required the iterator to wrap real return values in a container (basically, an optional/maybe monad) but then you have unwrapping overhead on every real return value, which is worse.

Re:Python 3.11: “Zero cost” exception handling by fouric on Wednesday October 06, 2021 @05:49PM (#28778939)
Couldn't the runtime just allocate a specific Python object representing the case where the iterator is complete? Make that object implementation-specific, hide it as best as you can, write documentation stating that users should not use this value directly, and if they do - they voided the warranty, and should expect evil to befall them. (ultimately, you can't prevent the user from doing really dumb things e.g. editing the Python binary directly)
Re:Python 3.11: “Zero cost” exception handling by dragonwriter on Wednesday October 06, 2021 @06:00PM (#28779042)
You do that with one thing, okay, maybe it works.

You do that with two or more of the protocols that Python has that use return values for return values ans exceptions for flow control signals and...you make it a lot harder to work with them, especially in conjunction.

Re:Python 3.11: “Zero cost” exception handling by fouric on Thursday October 07, 2021 @10:41AM (#28786902)
Can you give an example of this? I can't think of any myself - generators also raise a StopIteration exception, for instance, so they could use the same value.