Operator precedence problem

Michael Torrie torriem at gmail.com
Sun Jun 5 19:47:57 EDT 2016


On 06/05/2016 10:05 AM, Uri Even-Chen wrote:
> My suggestion: Never write expressions, such as  2 ** 3 ** 2 or even 2 * 4
> + 5, without parentheses. Always add parentheses - 2 ** (3 ** 2) (or (2 **
> 3) **2) or (2 * 4) + 5 (or 2 * (4 + 5)).

I can understand using parenthesis when operator precedence isn't
working the way you want or expect, but I certainly would not recommend
using it for basic arithmetic with multiplication, division, addition
and subtraction. The rules of precedence for multiplication and division
are well known and well-understood. If a language failed to implement
them that would be a bug.  I think for the simple things extraneous
parenthesis makes expressions more difficult for a human to parse
because he will tend to second guess himself owing to extra parens.




More information about the Python-list mailing list