
20.07.19 18:26, Guido van Rossum пише:
In an ideal world, needle is on the right. Let's replace needle with a constant: which of the following looks more natural?
for x in sequence: if x == 5: return True
or
for x in sequence: if 5 == x: return True
For me, 'x == 5' wins with a huge margin. (There is a subculture of C coders who have trained themselves to write '5 == x' because they're afraid of accidentally typing 'x = 5', but that doesn't apply to Python.)
Should we unify the stdlib? I'm not sure -- it feels like a sufficiently obscure area that we won't get much benefit out of it (people should fix their __eq__ implementation to properly return NotImplemented) and changing it would surely cause some mysterious breakage in some code we cannot control.
Thank you. The majority of the code uses needle on the right. There are just 6 places where it is on the left, and the half of them look copy-pasted, and in one place the C code differs from the corresponding Python implementation. There is an order more places where needle is on the right (and it is always on the right in the Python code). So I prefer to fix these few places to get rid of the minor inconsistency.