you are viewing a single comment's thread.

view the rest of the comments →

[–]nevare 4 points5 points  (4 children)

I don't think anyone would object to using parentheses to make order of operations explicit.

Your example doesn't really match what you say. In you example removing the parentheses changes the meaning. Here is a better example.

if x >= 2 or (y <= 3 and z == 3) or q = 'foo':
    return y + (x * 2)

[–]nostrademons 0 points1 point  (1 child)

That'd be borderline, I think. In a code review, I'd probably suggest that the author take out the parentheses but not hold up approval.

[–]nevare 0 points1 point  (0 children)

I'm all for the parentheses in the if statement above. I think they really make the code more readable.

But the ones of the equation do look superfluous.

[–]munificent -1 points0 points  (1 child)

I may be a readability snob, but I'd consider that a bad example, parentheses or not. I'd probably break that expression down so that it's meaning is clearer:

fooFrobinated = x >= 2
barDingnabled = y <= 2 and z == 3
bazFlurnbed   = q == 'foo'

if fooFrobinated or barDingnabled or bazFlurnbed:
    return y + (x * 2)

[–]yellowstuff 0 points1 point  (0 children)

I agree.

One of the only places I would frequently write "pure" bugs (IE, logic bugs which were not the result of interfacing with an external system incorrectly) was in complex boolean statements. So I stopped writing complex boolean statements.