Path: csiph.com!usenet.pasdenom.info!news.albasani.net!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'plenty': 0.07; 'assuming': 0.09; 'iterate': 0.09; 'testing,': 0.09; 'wrong,': 0.09; 'year?': 0.09; 'bug': 0.12; 'does,': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'intended.': 0.16; 'loop.': 0.16; 'skipping': 0.16; 'worse.': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'figures': 0.19; 'written': 0.21; '31,': 0.24; 'lets': 0.24; 'skip': 0.24; 'earlier': 0.24; 'possibly': 0.26; 'least': 0.26; 'header:In-Reply-To:1': 0.27; 'point': 0.28; 'chris': 0.29; 'am,': 0.29; 'message- id:@mail.gmail.com': 0.30; 'went': 0.31; 'code': 0.31; 'getting': 0.31; '(maybe': 0.31; '(since': 0.31; 'testing.': 0.31; 'fri,': 0.33; 'not.': 0.33; "can't": 0.35; 'something': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'right?': 0.36; 'done': 0.36; 'doing': 0.36; 'should': 0.36; 'starting': 0.37; 'expected': 0.38; 'to:addr:python-list': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'skip:u 10': 0.60; "you're": 0.61; 'more': 0.64; 'results': 0.69; 'ending': 0.78; 'darn': 0.84; 'ethan': 0.84; 'furman': 0.84; 'safer': 0.84; 'silently': 0.84; 'uptime': 0.84; 'imagine': 0.93; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=vp/zvlc6/CfKEd6GEoEeXlnWO4ORGZjJr55rbFN7HPY=; b=SSzKncBxukRxEpCy6up5dQafuxzYrs764jsldwr8W8gF8+4ItnZ12AHKkUv6J8MGOE 9hzi+of5NHpC1w/rw7v9m3dw7HI+g8FU5QrdmnZePaJok0ljLEwoU/T1khNIuTMAho5P AaAkOOfgsjVJuaJTq0+uXtZoxZ6sycXv0cD1PwWlJtdYj0jRSO9zlaP73FqZLxsCyvxV 6odEXdfY+dRUZ5lDUtnYy7cG787Gd3nTm2e6ZCXqwELXppvWwKa2D5qJ1jIrAe4KcgTL RYkaIQV2wdvXzHtjQEZ3XSSMnydvPBorhzJ8932GGynWwPatGF8C84wY2vZDrnvK7BoM 6mMw== MIME-Version: 1.0 X-Received: by 10.220.106.74 with SMTP id w10mr6181493vco.32.1369929369817; Thu, 30 May 2013 08:56:09 -0700 (PDT) In-Reply-To: <51A769F2.1050702@stoneleaf.us> References: <5f101d70-e51f-4531-9153-c92ee2486fd9@googlegroups.com> <51a1fc7b$0$30002$c3e8da3$5496439d@news.astraweb.com> <2abf4e9c-8c3b-4e2f-80c9-50c1f1d75c9d@googlegroups.com> <51a4b5a1$0$29966$c3e8da3$5496439d@news.astraweb.com> <04b90c02-833a-4bad-88ad-ab71178b8f79@googlegroups.com> <51a6df59$0$11118$c3e8da3@news.astraweb.com> <51A769F2.1050702@stoneleaf.us> Date: Fri, 31 May 2013 01:56:09 +1000 Subject: Re: Short-circuit Logic 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.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: 27 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369929372 news.xs4all.nl 16004 [2001:888:2000:d::a6]:36744 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46505 On Fri, May 31, 2013 at 1:02 AM, Ethan Furman wrote: > On 05/30/2013 05:58 AM, Chris Angelico wrote: >> If you iterate from 1000 to 173, you get nowhere. This is the expected >> behaviour; this is what a C-style for loop would be written as, it's >> what range() does, it's the normal thing. Going from a particular >> starting point to a particular ending point that's earlier than the >> start results in no iterations. The alternative would be an infinite >> number of iterations, which is far far worse. > > If the bug is the extra three zeros (maybe it should have been two), then > silently skipping the loop is the "far, far worse" scenario. With the > infinite loop you at least know something went wrong, and you know it pretty > darn quick (since you are testing, right? ;). You're assuming you can casually hit Ctrl-C to stop an infinite loop, meaning that it's trivial. It's not. Not everything lets you do that; or possibly halting the process will halt far more than you intended. What if you're editing live code in something that's had uninterrupted uptime for over a year? Doing nothing is much safer than getting stuck in an infinite loop. And yes, I have done exactly that, though not in Python. Don't forget, your start/stop figures mightn't be constants, so you might not see it in testing. I can't imagine ANY scenario where you'd actually *want* the infinite loop behaviour, while there are plenty where you want it to skip the loop, and would otherwise have to guard it with an if. ChrisA