[Python-Dev] cpython: Remove some extraneous parentheses and swap the comparison order to

Alexander Belopolsky alexander.belopolsky at gmail.com
Tue Jun 7 23:42:17 CEST 2011

>>> I agree with Georg: "if ('u' == typecode)" is not well readable,
>>> since you usually put the variable part on the left and the constant
>>> part on the right of an equal comparison.

I appear to be in the minority here, but this particular example does
not strike me as egregiously unreadable.  To the contrary, by bringing
the constant to the front, this form saves me from having to read to
the end of the line.  The same mental economy appears when constants
are brought to the front of chained if-elif cases in Python:

if 'a' == typecode:
elif 'b' == typecode:

is slightly more readable than the more traditional alternative.
Probably because I can mentally ignore the "== typecode" part and see
the switch structure more clearly.

Either way, I don't see a big issue here and I would keep "len == 0"
intact even if I reordered typecode == 'u' as Brett did.  The only
consistency that I would enforce is to use the same order in the
chained if-elif cases, but otherwise this should be left to the
discretion of the author.

More information about the Python-Dev mailing list