Re:Python 3.11: “Zero cost” exception handling
by stevesimmons on Wednesday October 06, 2021 @11:00AM
(#28773952)
The difference in your "which of the two look better" example is:
(a) has one dict operation plus an exception which rarely occurs and is nearly zero cost if it doesn't.
versus
(b) has nearly always two dict operations, plus a possibly incorrect assumption that the dict will not be mutated between the "if key in dict" and "dict[key]" operations.
Re:Python 3.11: “Zero cost” exception handling
by detaro on Wednesday October 06, 2021 @12:13PM
(#28774852)
No, you can have multiple threads in a python app. And while it promises to keep many things atomic, code like that can be interrupted between each line at minium.
(a) has one dict operation plus an exception which rarely occurs and is nearly zero cost if it doesn't.
versus
(b) has nearly always two dict operations, plus a possibly incorrect assumption that the dict will not be mutated between the "if key in dict" and "dict[key]" operations.