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

R. David Murray rdmurray at bitdance.com
Wed Jun 8 03:16:32 CEST 2011

On Tue, 07 Jun 2011 17:42:17 -0400, Alexander Belopolsky <alexander.belopolsky at gmail.com> wrote:
> ..
> >>> 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.

I don't do much C coding, so I don't have the right to an opinion on
that (FWIW, I find constant-first jarring).  But I'd hate to see the
above in python code.  The fact that you like it because it makes it
easier to read as a switch-like statement should instead tell you that
it is time to refactor the code.

R. David Murray           http://www.bitdance.com

More information about the Python-Dev mailing list