Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!newsfeed.xs4all.nl!newsfeed6.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.010 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'debug': 0.03; 'exception,': 0.07; 'something,': 0.07; 'subject:while': 0.07; 'used.': 0.07; 'python': 0.08; '*i*': 0.09; 'loop.': 0.09; 'reply- to:addr:comp.lang.python': 0.09; 'throw': 0.09; 'to:addr:comp.lang.python': 0.09; 'c++': 0.12; 'cc:addr:python- list': 0.15; '"while': 0.16; '++i)': 0.16; 'boolean': 0.16; 'driscoll': 0.16; 'evaluates': 0.16; 'iterator': 0.16; 'iterator.': 0.16; 'throws': 0.16; 'wrote:': 0.16; 'converted': 0.18; 'slightly': 0.19; 'cc:no real name:2**0': 0.21; 'header:In- Reply-To:1': 0.22; 'faster,': 0.23; 'there.': 0.25; 'pm,': 0.26; "i'm": 0.27; 'bit': 0.28; 'cc:addr:python.org': 0.29; 'definition': 0.30; '*and*': 0.30; 'least': 0.30; 'adds': 0.32; 'implementing': 0.32; 'idea': 0.32; "can't": 0.32; 'header:User- Agent:1': 0.33; 'from:addr:googlemail.com': 0.34; 'advocate': 0.34; 'builds': 0.34; 'integer': 0.34; 'latter': 0.34; 'typical': 0.34; 'received:209.85.160': 0.35; 'cc:2**1': 0.36; 'two': 0.37; 'but': 0.37; 'received:google.com': 0.37; 'moment,': 0.38; 'some': 0.38; 'received:209.85': 0.38; 'think': 0.38; 'should': 0.38; 'processing': 0.39; "i'd": 0.39; 'point': 0.39; 'why': 0.39; 'called': 0.39; 'received:209': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'more': 0.61; 'accepts': 0.64; 'harder': 0.64; 'same,': 0.67; 'header:Reply-To:1': 0.71; 'reply-to:no real name:2**0': 0.72; 'hate': 0.73; 'reply-to:addr:googlegroups.com': 0.74; '06:05': 0.84; '8bit%:60': 0.84; '8bit%:61': 0.84; 'c..': 0.84; 'difference.': 0.84; 'hair,': 0.84; 'idiom': 0.84; 'place?': 0.84; 'skip:2 50': 0.91; 'supporter': 0.91 Newsgroups: comp.lang.python Date: Mon, 23 Jan 2012 14:42:02 -0800 (PST) In-Reply-To: Complaints-To: groups-abuse@google.com Injection-Info: glegroupsg2000goo.googlegroups.com; posting-host=112.104.167.201; posting-account=5JdMBQoAAABHnS4mjpqEzxnmWtgiiVNw References: <4F1AC1D4.2080402@gmail.com> <4F1DA186.1040807@wisc.edu> User-Agent: G2/1.0 X-Google-Web-Client: true MIME-Version: 1.0 Subject: Re: while True or while 1 From: 88888 Dihedral To: comp.lang.python@googlegroups.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Cc: python-list@python.org X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list Reply-To: comp.lang.python@googlegroups.com List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Message-ID: Lines: 58 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1327358527 news.xs4all.nl 6870 [2001:888:2000:d::a6]:39774 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:19295 =E5=9C=A8 2012=E5=B9=B41=E6=9C=8824=E6=97=A5=E6=98=9F=E6=9C=9F=E4=BA=8CUTC+= 8=E4=B8=8A=E5=8D=884=E6=97=B650=E5=88=8611=E7=A7=92=EF=BC=8CAndrea Crotti= =E5=86=99=E9=81=93=EF=BC=9A > On 01/23/2012 06:05 PM, Evan Driscoll wrote: > > > > To play devil's advocate for a moment, if you have the choice between= =20 > > two ways of writing something, A and B, where both are basically the=20 > > same in terms of difficulty to write, difficulty to maintain, and=20 > > difficulty to understand, but A is faster than B, even if just by a=20 > > hair, why NOT write A? > > > > It's like 'iter++' vs '++iter' in a C++ for loop. For ints, or for=20 > > some iterators with optimization, it makes no difference. But the=20 > > latter will be faster in debug builds, and *might* be faster in=20 > > release builds if you have a complicated iterator. So why NOT make=20 > > for(...; ...; ++i) the typical way of writing a for loop? > > > > In the Python world, is 'while 1' any harder to understand than 'while= =20 > > True'? I'm about as staunch a supporter as you'll find for the idea=20 > > that 'while 1' should throw an exception, and even *I* think that=20 > > 'while 1' is about the least-offensive idiom out there. If 'while 1'=20 > > throws you off, I'd hate to see what you do when you learn that Python= =20 > > accepts loops like 'while x' where the condition evaluates to true if= =20 > > x is a non-zero integer and false if x is 0. > > > > > > All that said, I like the 'while "stuff to do"' idea. > > > > Evan >=20 > I think it's not the same, iter++ or ++iter is exactly the same in terms= =20 > of readability, so of course > if one might be a bit faster, it should be used. >=20 > while 1 works because the 1 is converted to boolean automatically, but=20 > why not just writing a boolean > in the first place? >=20 > It's not bad of course but to me it's not very Pythonic, and reminds me C= . > At that point I also prefer the "while 'might be long loop'" idea, which= =20 > at least > adds some value *and* it might be very slightly faster too. A fake generator that can't be cascaded for more processing can be called an iterator by the definition of an iterator.=20 But that is miss-leading in implementing silly trivial non-qualified iterat= ors.