Path: csiph.com!usenet.pasdenom.info!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed1.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.014 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'python.': 0.02; 'intermediate': 0.07; 'level,': 0.07; 'practice,': 0.07; 'referring': 0.07; 'iterate': 0.09; 'shame': 0.09; 'useless': 0.09; 'uses.': 0.09; 'python': 0.11; 'suggest': 0.14; 'wrote': 0.14; '"for"': 0.16; '"in"': 0.16; 'expression,': 0.16; 'indent': 0.16; 'loops': 0.16; 'option:': 0.16; 'readability': 0.16; 'sees': 0.16; 'sequence:': 0.16; 'subject:python': 0.16; 'wrote:': 0.18; '>>>': 0.22; 'aug': 0.22; 'coding': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'exists': 0.24; "shouldn't": 0.24; 'header :In-Reply-To:1': 0.27; '+0100,': 0.31; '>>>>': 0.31; "d'aprano": 0.31; 'steven': 0.31; 'subject:end': 0.31; 'writes:': 0.31; 'option': 0.32; 'regular': 0.32; 'fri,': 0.33; 'problem': 0.35; 'except': 0.35; 'but': 0.35; 'there': 0.35; 'really': 0.36; 'done,': 0.36; 'sequence': 0.36; 'possible': 0.36; 'too': 0.37; 'saves': 0.38; 'to:addr:python-list': 0.38; 'fact': 0.38; 'rather': 0.38; 'short': 0.38; 'bad': 0.39; 'structure': 0.39; 'to:addr:python.org': 0.39; 'how': 0.40; 'new': 0.61; 'matter': 0.61; 'strategy': 0.64; 'more': 0.64; 'levels': 0.65; 'here': 0.66; 'clearer': 0.84; 'fourth': 0.84; 'gains': 0.84; 'pardon': 0.84; 'received:192.168.1.7': 0.84; 'received:195.238': 0.84; 'received:195.238.6': 0.84; 'received:belgacom.be': 0.84; 'received:isp.belgacom.be': 0.84; 'sometimes.': 0.84; 'suits': 0.84; 'absolutely': 0.87; 'dare': 0.91; '2013': 0.98 X-Belgacom-Dynamic: yes X-IronPort-Anti-Spam-Filtered: true X-IronPort-Anti-Spam-Result: ApMBAIJ/I1JQyEM1/2dsb2JhbAANTIc0vUWBNIMYAQEBBCMPAQU0DBELGAICBRYLAgIJAwIBAgEPNhMGAgKHbAOmcXSHbg1XiRGBKYtmgncWglOBNAOWDIFpjDeIUQ Date: Sun, 01 Sep 2013 19:58:14 +0200 From: Antoon Pardon User-Agent: Mozilla/5.0 (X11; Linux i686; rv:17.0) Gecko/20130704 Icedove/17.0.7 MIME-Version: 1.0 To: python-list@python.org Subject: Re: semicolon at end of python's statements References: <1377735506.18906.15.camel@debian> <1FETt.52607$Mw4.14965@fx15.am4> <7wob8gywds.fsf@benfinney.id.au> <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> In-Reply-To: <52213435$0$6599$c3e8da3$5496439d@news.astraweb.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 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: 62 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1378058364 news.xs4all.nl 15959 [2001:888:2000:d::a6]:45551 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:53421 Op 31-08-13 02:09, Steven D'Aprano schreef: > On Fri, 30 Aug 2013 11:32:17 +0100, Fábio Santos wrote: > >> On 29 Aug 2013 23:20, "Ben Finney" wrote: >>> >>> Fábio Santos writes: >>> >>>> It is a shame that this is not possible in python. for..if exists in >>>> comprehensions and not in regular loops but that would be nice >>>> sometimes. >>> >>> So you use it in a generator expression, and iterate over the >>> generator: >>> >>> for foo in (spam for spam in sequence if predicate(spam)): >>> process(spam) >>> >>> That way, there's no need for new syntax. >> >> The problem I have with that strategy is that it is repetitive and >> hinders readability. You wrote "for" and "in" twice, and spam (a pretty >> useless intermediate variable) thrice! > > There is no need for spam to be "intermediate", and the fact that it > shouldn't be is demonstrated by Ben's error in referring to "process > (spam)" instead of "process(foo)". > > We really are spoiled for choice here. We can write any of these: > > # Option 1 > for spam in sequence: > if predicate(spam): > process(spam) > > # Option 2 > for spam in filter(predicate, sequence): > process(spam) > > # Option 3 > for spam in (spam for spam in sequence if predicate(spam)): > process(spam) > > > Adding a fourth option: > > for spam in sequence if predicate(spam): > process(spam) > > saves absolutely nothing except a line and an indent level, neither of > which are in short supply, and gains nothing in readability over Option 1. I find this rather disenginuous. Dare to suggest here that python might benetif by incluidng end markers for its suits because it would make it clearer how many indent levels were done, and chances are someone here will suggest that too many indent levels are a sign of bad coding practice, but when someone suggests a change that would allow him to structure his program more like how he sees it and indent levels are not short in supply, suggesting there is no problem, no matter how many one uses. -- Antoon Pardon