Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!ecngs!feeder2.ecngs.de!newsfeed.freenet.ag!news2.euro.net!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.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'say,': 0.05; 'subject:skip:s 10': 0.05; 'line:': 0.07; 'ugly': 0.07; 'through.': 0.09; 'violates': 0.09; 'cc:addr:python-list': 0.10; 'sat,': 0.15; 'complains': 0.16; 'construct.': 0.16; 'downside': 0.16; 'fine.': 0.16; 'iterates': 0.16; 'oct': 0.16; 'then?': 0.16; 'to:addr:pearwood.info': 0.16; 'to:addr:steve+comp.lang.python': 0.16; "to:name:steven d'aprano": 0.16; 'true:': 0.16; 'wrote:': 0.17; "shouldn't": 0.17; 'beauty': 0.22; 'received:mail- bk0-f46.google.com': 0.22; 'cc:2**0': 0.23; 'solutions.': 0.23; 'somebody': 0.23; 'statement': 0.23; 'cc:no real name:2**0': 0.24; 'pass': 0.25; 'cc:addr:python.org': 0.25; 'header:In-Reply-To:1': 0.25; 'received:209.85.214.46': 0.27; 'message- id:@mail.gmail.com': 0.27; 'lines': 0.28; "d'aprano": 0.29; 'high.': 0.29; 'obliged': 0.29; 'steven': 0.29; 'code': 0.31; '+0200,': 0.33; 'skip:d 20': 0.34; 'received:google.com': 0.34; 'problem,': 0.35; 'pm,': 0.35; 'received:209.85': 0.35; 'something': 0.35; 'there': 0.35; 'really': 0.36; 'but': 0.36; 'does': 0.37; 'two': 0.37; 'received:209': 0.37; 'subject:: ': 0.38; 'received:209.85.214': 0.39; 'header:Received:5': 0.40; 'your': 0.60; 'first': 0.61; 'risk': 0.66; 'as:': 0.75; 'dry': 0.84; 'gelonida': 0.84; 'convinced': 0.93 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc:content-type; bh=iHy3ikeG/N3A4hN61CnkakBnmf8OqwDUwmffneCrHpM=; b=Gv2+ds+9a2BeN4doqz/Fq9EAienrHv3Hiai5OybMioKoL8+z+0bsDE4kcP20AywcTm MSc+VBFqOgxztgchNd+D4G9w+4eA+YPD5JL5SEScR7FcjLnWb6T2qwaAY5iVbq3HUo6n GktWwBmZ4YQOUShfRWPbT+g89V3witeF0hzfDxo/RwUZlZOi4zT0NQ5O29WqzvGB6i1W OTGvLUKfzN/WIKIiQLb7Y5w6BkSPXZKN+OhYBObRAibCQGtpEAIJztyudveYAzeVQppw +JFsQf9LkobcUtgd7wsmb78zAKv+BDSJJOK2T3tbtMY6i3+y7BUZC/kkBH8/2UchiKBb DTcg== MIME-Version: 1.0 In-Reply-To: <508c810f$0$29967$c3e8da3$5496439d@news.astraweb.com> References: <508c810f$0$29967$c3e8da3$5496439d@news.astraweb.com> From: Devin Jeanpierre Date: Sun, 28 Oct 2012 01:57:45 -0400 Subject: Re: attaching names to subexpressions To: "Steven D'Aprano" Content-Type: text/plain; charset=UTF-8 Cc: python-list@python.org 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: 53 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1351403908 news.xs4all.nl 6874 [2001:888:2000:d::a6]:33714 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:32302 On Sat, Oct 27, 2012 at 8:49 PM, Steven D'Aprano wrote: > On Sat, 27 Oct 2012 15:03:38 +0200, Gelonida N wrote: > >> line = complex_exression >> while line: >> do something with(line) >> line = complex_expression >> >> violates clearly the DRY principle and the risk to change one line but >> not the other is high. -- snip -- > while True: > line = function(x, y, z) > if not line: > break > big ugly block of code > > > There you go. DRY. >> The 'canonical way' >> while True: >> line = complex_expression >> if not line: >> break >> do_something_with(line) >> >> avoids this problem, but I was never really convinced about the beauty / >> readbility of this construct. >> >> In >> my opinion I shouldn't be obliged to read any of the indented lines of >> the while statement on a first 'visual' pass through somebody elses code >> and still be able to see what the loop iterates through. > > Fine. Then write your code as: > > line = function(x, y, z) > while line: > do something with(line) > line = function(x, y, z) > We have a problem, and two solutions. Solution 1 has downside A, and solution 2 has downside B. If he complains about downside A, you say, well, use solution 2. If he complains about downside B, you say, well, use solution 1. What if he wants to avoid both downsides A and B? What solution does he use then? -- Devin