Path: csiph.com!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!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; 'from:addr:ethan': 0.09; 'from:addr:stoneleaf.us': 0.09; 'from:name:ethan furman': 0.09; 'iterate': 0.09; 'message-id:@stoneleaf.us': 0.09; 'received:184.172': 0.09; 'received:gator410.hostgator.com': 0.09; 'testing,': 0.09; 'wrong,': 0.09; '~ethan~': 0.09; 'bug': 0.12; 'does,': 0.16; 'roy': 0.16; 'skipping': 0.16; 'worse.': 0.16; 'zeros': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'written': 0.21; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'earlier': 0.24; 'source': 0.25; 'least': 0.26; 'code:': 0.26; 'header:In-Reply- To:1': 0.27; 'point': 0.28; 'correct': 0.29; 'chris': 0.29; 'am,': 0.29; '(which': 0.31; 'went': 0.31; '(maybe': 0.31; '(since': 0.31; 'accidentally': 0.31; 'bug?': 0.31; 'something': 0.35; 'really': 0.36; 'right?': 0.36; 'charset:us-ascii': 0.36; 'should': 0.36; 'turn': 0.37; 'starting': 0.37; 'expected': 0.38; 'somebody': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'that,': 0.38; 'to:addr:python.org': 0.39; 'received:173': 0.61; 'simply': 0.61; "you're": 0.61; '30,': 0.65; 'received:69.56': 0.68; 'smith': 0.68; 'results': 0.69; 'ending': 0.78; 'darn': 0.84; 'received:69.56.148': 0.84; 'received:69.56.148.22': 0.84; 'silently': 0.84; 'not:': 0.91; '2013': 0.98 Date: Thu, 30 May 2013 08:02:10 -0700 From: Ethan Furman User-Agent: Mozilla/5.0 (X11; Linux i686; rv:16.0) Gecko/20121010 Thunderbird/16.0.1 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Short-circuit Logic 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> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-AntiAbuse: This header was added to track abuse, please include it with any abuse report X-AntiAbuse: Primary Hostname - gator410.hostgator.com X-AntiAbuse: Original Domain - python.org X-AntiAbuse: Originator/Caller UID/GID - [47 12] / [47 12] X-AntiAbuse: Sender Address Domain - stoneleaf.us X-BWhitelist: no X-Source: X-Source-Args: X-Source-Dir: X-Source-Sender: ([10.1.74.105]) [173.12.184.238]:50193 X-Source-Auth: ethan+stoneleaf.us X-Email-Count: 1 X-Source-Cap: dG9idWs7dG9idWs7Z2F0b3I0MTAuaG9zdGdhdG9yLmNvbQ== 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: 28 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1369929032 news.xs4all.nl 15950 [2001:888:2000:d::a6]:60997 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:46504 On 05/30/2013 05:58 AM, Chris Angelico wrote: > On Thu, May 30, 2013 at 10:40 PM, Roy Smith wrote: >> if somebody were to accidentally drop three zeros into the source code: >> >>> x = 1000 >>> while x < 173: >>> print(x) >>> x += 1 >> >> should the loop just quietly not execute (which is what it will do >> here)? Will that make your program correct again, or will it simply >> turn this into a difficult to find bug? If you're really worried about >> that, why not: > > 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? ;). -- ~Ethan~