Re:Python 3.11: “Zero cost” exception handling
by alex_smart on Wednesday October 06, 2021 @01:17PM
(#28775660)
I don't think python has the mindset of "exceptions are extremely rare". That is probably what the OC meant by python being "a language where idiomatic control flow uses exceptions". As an example, every iterator in python signals its end by throwing a StopIteration exception. So, every "for x in iter" has the interpreter throwing and catching an exception.
Re:Python 3.11: “Zero cost” exception handling
by masklinn on Wednesday October 06, 2021 @02:15PM
(#28776322)
> I don't think python has the mindset of "exceptions are extremely rare".
No it does not, that's my point: when exceptions are extremely rare, as in C++ or Java, having the "no exception" case be free at additional expense in the "exception" case is an excellent tradeoff, because the latter should happen extremely rarely so even if the costs are ridiculous you'll have more than made them by all the cases where you got the "no exception" run for free.
In Python where exceptions are common however, making one case free at the expense of the other is less interesting a proposition, and is more of a balancing act: you don't want to overly penalise exceptions-heavy code as that is considered normal and idiomatic.
Seems like the opposite: if exceptions are extremely rare then you want to optimise the case where they’re not raised, at the cost of the other one.
If exceptions are common then it matters a lot less, you may even want to avoid 0ce depending on the impact on the raised case.