[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Operator precedence problem

On 2016-06-06, Chris Angelico <rosuav at> wrote:
> On Tue, Jun 7, 2016 at 1:27 AM, Jon Ribbens
><jon+usenet at> wrote:
>>>> You should put brackets around expressions when it's at all unclear
>>>> what the meaning is. You could think of them a bit like "active
>>>> comments" I suppose.
>>> Your code should keep noise to the minimum.
>> Sensible and beneficial comments aren't "noise".
> In that case, please never insult the intelligence of your future
> readers by including any of these parentheses:
> x = 1 + (2 * 3)

I'm not sure what your point is. Yes, obviously you can take anything
to ridiculous extremes - that's why I said "sensible".

> value = 77 if (x % 2) else (70*7)

I'm not convinced that one isn't actually a good idea. It does seem
to aid the readability (especially if you space '70 * 7' properly).
If the expressions were any more complex then it would be even more
likely to be a good idea.

> And if your readers have to figure out what 3**3**3 is interpreted as,
> there should be an interactive interpreter around. Or here - try
> something cute:
>>>> 2**2**-1

I can't tell now if you're agreeing with me or disagreeing, because
you started out sounding like you were disagreeing but then provided
an example that helps prove my point.