Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.009 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.04; 'operator': 0.05; 'continuation': 0.07; 'operator,': 0.09; 'tuple': 0.09; 'programmer': 0.10; 'am,': 0.12; 'subsequent': 0.15; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'ignores': 0.16; 'parentheses': 0.16; 'parsed': 0.16; 'unary': 0.16; 'syntax': 0.16; 'wrote:': 0.16; 'wed,': 0.17; '>>>': 0.18; "doesn't": 0.22; 'header:In-Reply-To:1': 0.22; 'pm,': 0.24; 'skip:( 30': 0.24; 'aug': 0.24; 'code': 0.25; 'separate': 0.28; 'message-id:@mail.gmail.com': 0.29; 'lines': 0.30; 'booth': 0.30; 'error': 0.32; 'chris': 0.32; 'error.': 0.32; 'usually': 0.32; 'too': 0.33; 'to:addr:python-list': 0.33; 'done': 0.34; 'assignment': 0.34; 'forces': 0.34; 'read,': 0.36; 'another': 0.37; 'languages': 0.37; 'but': 0.37; 'something': 0.37; 'some': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'easier': 0.38; 'skip:o 20': 0.38; 'subject:: ': 0.39; 'to:addr:python.org': 0.39; "i'd": 0.40; 'might': 0.40; 'happens': 0.40; 'results': 0.61; 'legal': 0.70; 'imagine': 0.71; 'subject:line': 0.73; '10:56': 0.84; 'risk.': 0.84; 'sommers': 0.84; "everything's": 0.91; 'arise': 0.96 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type:content-transfer-encoding; bh=Ni2SbpAhZxsSWJrEqyU6CQONMWfiwbRbAV5tNhzDUgc=; b=JT1r9PcZhXeFqUEiVg37syLOc2dPqZe7DAqDBaS7rbOWvMtVPhr7qlhQPUQroD/t42 pDt13YMDd+xwPmfJtU8QmwpPVVqpWUrrbxU+gHrCMKxNEEtZmF1TPgZvzyH2soeCJyw2 IRsk/MTPrEw40KldJFBJ1I56N3pkrGjKQOu5I= MIME-Version: 1.0 In-Reply-To: References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 10 Aug 2011 13:42:30 +0100 Subject: Re: allow line break at operators From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 48 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312980152 news.xs4all.nl 23943 [2001:888:2000:d::a6]:56814 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11116 On Wed, Aug 10, 2011 at 1:25 PM, Duncan Booth wrote: > Chris Angelico wrote: > >> On Wed, Aug 10, 2011 at 10:56 AM, Dan Sommers >> wrote: >>> In terms of easier to read, I find code easier to read when the >>> operators are at the beginnings of the lines (PEP 8 notwithstanding): >>> >>> =A0 =A0x =3D (someobject.somemethod(object3, thing) >>> =A0 =A0 =A0 =A0 + longfunctionname(object2) >>> =A0 =A0 =A0 =A0 + otherfunction(value1, value2, value3)) >>> >> >> Without the parentheses, this is legal but (probably) useless; it >> applies the unary + operator to the return value of those functions. > > No, in some other languages it might be legal, but this is Python. > without the parentheses it is a syntax error. It would be parsed as three separate statements. The only reason it would be a syntax error would be because of the indentation, which is not what I'd call reliable; it happens to catch this case, because assignment doesn't allow subsequent lines to be indented, but nothing forces continuation lines to be indented. x =3D (5 +4) x =3D 5 +4 What we have is a strangeness that can arise when a programmer ignores something that is often insignificant; spare parentheses usually don't matter. Another potential danger is the similarity with tuple creation: x =3D (someobject.somemethod(object3, thing) =A0 =A0 + longfunctionname(object2) =A0 =A0 + otherfunction(value1, value2, value3),) This is a tuple with one element. Not too bad with the + operator, but imagine if everything's done with method chaining on . which results in the , being nearly indistinguishable. Not an insurmountable problem, but a potential risk. ChrisA