Operator precedence problem

Marko Rauhamaa marko at pacujo.net
Mon Jun 6 11:22:42 EDT 2016


Jon Ribbens <jon+usenet at unequivocal.co.uk>:

> On 2016-06-06, Marko Rauhamaa <marko at pacujo.net> wrote:
>> You *can* assume other people have read the spec. Even more
>> importantly, you can assume the Python interpreter complies with the
>> spec.
>
> Obviously the latter is true (or at least, it's true except when it's
> false). The former however is not true.

Well, of course nobody knows the whole spec. However, you should write
your code assuming they do. Different people have different gaps in
their knowledge:

 * Somebody might not be aware of chained comparisons: a < b < c

 * Somebody might not know of the "else" branch of a "for" statement.

 * Somebody might not know of the if-else expression: a if b else c

However, there's no need to avoid those facilities that are there for
people to use them. What people are unclear about they can check in the
spec, which is readily available.

> 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.


Marko



More information about the Python-list mailing list