Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Random832 Newsgroups: comp.lang.python Subject: Re: Operator precedence problem Date: Mon, 06 Jun 2016 09:57:01 -0400 Lines: 28 Message-ID: References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de zGUgI2H9cmHOmv+v8hQTdAXFmaJihZ3IVFP3r2HL++Hw== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.005 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; 'expressions': 0.07; '**)': 0.09; 'precedence': 0.09; 'received:internal': 0.09; 'assume': 0.11; '<>.': 0.11; '"and"': 0.16; '"or"': 0.16; '2016': 0.16; 'bitwise': 0.16; 'expressions,': 0.16; 'message- id:@webmail.messagingengine.com': 0.16; 'operators,': 0.16; 'parentheses': 0.16; 'precedence.': 0.16; 'readers,': 0.16; 'received:10.202': 0.16; 'received:10.202.2': 0.16; 'received:66.111': 0.16; 'received:66.111.4': 0.16; 'received:io': 0.16; 'received:messagingengine.com': 0.16; 'received:psf.io': 0.16; 'tripped': 0.16; 'wrote:': 0.16; '(not': 0.20; 'lawrence': 0.22; 'subject:problem': 0.22; 'header:In-Reply-To:1': 0.24; 'discussion': 0.24; 'mon,': 0.24; 'skip:" 20': 0.26; 'equivalent': 0.27; 'arithmetic': 0.29; 'operators': 0.29; 'sure,': 0.29; "i'm": 0.30; 'code': 0.30; 'relative': 0.30; '"the': 0.32; 'getting': 0.33; 'except': 0.34; 'this?': 0.34; 'on,': 0.35; 'ones': 0.35; 'something': 0.35; 'but': 0.36; 'lines': 0.36; 'basic': 0.36; 'monday,': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'received:10': 0.37; 'aspects': 0.37; 'received:66': 0.38; 'sure': 0.39; 'along': 0.39; 'to:addr:python.org': 0.40; 'header:Message- Id:1': 0.61; 'more': 0.63; 'strictly': 0.64; 'goal': 0.64; 'url:co': 0.65; 'url:2011': 0.75; 'obvious': 0.76; 'url:i': 0.77; 'url:10': 0.79; 'url:jpg': 0.79; 'low': 0.83; 'url:dailymail': 0.91; 'confidence': 0.95 DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d=fastmail.com; h= content-transfer-encoding:content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-sasl-enc :x-sasl-enc; s=mesmtp; bh=kYSpY/mK4NLRXCRLZYqSXh3xBzg=; b=pHNfBa SHGrk/9chpr2CnUSAC0hO3bHumHGrXnyusgactKqUBKlPh639MqYRtdbvcenMo8E UZuCi0Z7RgOcKZ38RLNXRe0tkvhkz3NFDcBUuPBeQsgTLvloDmgs/0/PCnsHt74i THd5rqQcb6w88jSJeujuFt9FDHLA+YrnP4ST8= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-sasl-enc:x-sasl-enc; s=smtpout; bh=kYSpY/mK4NLRXCR LZYqSXh3xBzg=; b=PMpryIDymt54tu3VrIgD6fq8kpMxal2B6ev849nx1ySxcQJ S8r0t9mqGT7F5xjGcagz5+4LhIvq/waTnT9OChVrpUJF1CO/B3HicaZSXgQVkWDm iCFk14wAjfGSVdxJ8ZUWcyESAXQat19q9//Te0BbP895QjHCRMqaK8LFJX6w= X-Sasl-Enc: BCfQ+oXKpKgkliwG4AklmQmELsPSYA1qQlbNVanQUTfG 1465221421 X-Mailer: MessagingEngine.com Webmail Interface - ajax-7f2506ab In-Reply-To: <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: <1465221421.1069788.629246361.60094337@webmail.messagingengine.com> X-Mailman-Original-References: <816c651a-d0ae-4e23-a5b2-72a8f7398468@googlegroups.com> <3ff71354-461a-4635-8d1a-c879243e39a8@googlegroups.com> <2a577a90-3a39-4d8f-90fa-4a00fd4f06a3@googlegroups.com> Xref: csiph.com comp.lang.python:109564 On Mon, Jun 6, 2016, at 01:46, Lawrence D=E2=80=99Oliveiro wrote: > On Monday, June 6, 2016 at 4:06:20 AM UTC+12, Uri Even-Chen wrote: > > Never write expressions, such as 2 ** 3 ** 2 or even 2 * 4 > > + 5, without parentheses. >=20 > That leads to the code equivalent of > . Okay, can we settle on, as a principle, "the basic arithmetic operators (not to include **) are the only ones whose precedence can be presumed to be obvious to all readers, and other expressions may/should have parentheses to make it more clear, even when not strictly necessary to the meaning of the expression"? Sure, it's obvious to _me_ that << and >> have higher precedence than & and |, and that "and" has a higher precedence than "or", but can I assume the other people know this? And I don't know offhand the relative precedence of non-conceptually-related groups of operators, except that I'm pretty sure "and" and "or" have very low precedence. [To keep this on-topic, let's assume that this discussion has a goal of getting something along the lines of "always/sometimes/never use "unnecessary" parentheses" into PEP7/PEP8. Speaking of, did you know that C has lower precedence for the bitwise operators &^| than for comparisons? That was something that tripped me up for a very long time and undermined my confidence as to other aspects of the bitwise operators]