Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'operator': 0.05; 'encouraged.': 0.09; 'am,': 0.12; 'skip:f 30': 0.13; 'alternative,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'handy': 0.16; 'imho,': 0.16; 'included,': 0.16; 'pythonic': 0.16; 'self,': 0.16; 'wrote:': 0.16; 'wed,': 0.17; '>>>': 0.18; 'header:In-Reply-To:1': 0.22; 'aug': 0.24; 'code': 0.25; 'code,': 0.28; 'message-id:@mail.gmail.com': 0.29; 'chris': 0.32; 'list': 0.32; "isn't": 0.33; 'it.': 0.33; 'there': 0.33; 'to:addr:python-list': 0.33; 'that,': 0.33; 'thread': 0.37; 'but': 0.37; 'steven': 0.38; 'received:google.com': 0.38; 'received:209.85': 0.38; 'should': 0.38; 'subject:: ': 0.39; 'getting': 0.39; 'to:addr:python.org': 0.39; "it's": 0.40; 'more': 0.60; 'six': 0.61; 'law': 0.63; 'violation': 0.67; 'as:': 0.70; 'subject:line': 0.73 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; bh=b3fo3IMEsJRZEk030X1q7nisp1r1ObJENSey5/IJuT4=; b=Qymf7/dvNFR4X7sbAc9E5l5P/zBKTFVflzwk2UevSbNctRk52ONBxtCtewvgL7gPQ3 ylP8tmtUByD/uwvwGxwnzR4L8CfJvGFlujsaDtzNoIqJcuN1/NvKM1+wlvKesrikLJU0 pStVfVZHOUI+i4cjsSSweo+G3Zf4VO7h/Ehek= MIME-Version: 1.0 In-Reply-To: <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> References: <1312951356.77394.YahooMailNeo@web121518.mail.ne1.yahoo.com> <4e424208$0$29965$c3e8da3$5496439d@news.astraweb.com> Date: Wed, 10 Aug 2011 09:39:55 +0100 Subject: Re: allow line break at operators From: Chris Angelico To: python-list@python.org Content-Type: text/plain; charset=ISO-8859-1 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: 26 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1312965604 news.xs4all.nl 23913 [2001:888:2000:d::a6]:34564 X-Complaints-To: abuse@xs4all.nl Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!bete-des-vosges.org!feed.ac-versailles.fr!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!feeder.news-service.com!newsfeed.xs4all.nl!newsfeed6.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:11103 On Wed, Aug 10, 2011 at 9:32 AM, Steven D'Aprano wrote: >>> Of course, the dot operator is also included, which may facilitate method >>> chaining: >>> >>> x = svg.append( 'circle' ). >>> r(2).cx(1).xy(1). >>> foreground('black').bkground('white') > > If you are chaining six dots like that, you are in gross violation of the > Law Of Demeter. That is poor code, and should be discouraged, not > encouraged. I would only accept that this is poor code IF there is a viable alternative, such as: x = svg.append(circle(r=2,cx=1,xy=1,foreground='black',bkground='white')) This would, imho, be a more Pythonic way to do it. But if this isn't available, and if the methods already return self, then I see nothing wrong with chaining. It's a handy way of getting additional mileage out of lambdas and list comps when writing one-liners. :) (Cue long thread about whether or not one-liners are Pythonic.) Chris Angelico