Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #19286

Re: while True or while 1

Path csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!gegeweb.org!de-l.enfer-du-nord.net!feeder1.enfer-du-nord.net!newsfeed.eweka.nl!feeder3.eweka.nl!81.171.88.15.MISMATCH!eweka.nl!feeder.eweka.nl!62.179.104.142.MISMATCH!amsnews11.chello.com!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
Return-Path <andrea.crotti.0@gmail.com>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.002
X-Spam-Evidence '*H*': 1.00; '*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; 'throw': 0.09; 'c++': 0.12; 'cc:addr:python-list': 0.15; 'received:74.125.82.44': 0.15; 'received:mail-ww0-f44.google.com': 0.15; '"while': 0.16; '++i)': 0.16; 'boolean': 0.16; 'driscoll': 0.16; 'evaluates': 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; 'cc:2**0': 0.25; 'there.': 0.25; 'pm,': 0.26; "i'm": 0.27; 'bit': 0.28; 'cc:addr:python.org': 0.29; '*and*': 0.30; 'least': 0.30; 'adds': 0.32; 'idea': 0.32; 'message-id:@gmail.com': 0.33; 'header :User-Agent:1': 0.33; 'advocate': 0.34; 'builds': 0.34; 'integer': 0.34; 'latter': 0.34; 'typical': 0.34; 'received:74.125.82': 0.34; 'two': 0.37; 'but': 0.37; 'received:74.125': 0.37; 'received:google.com': 0.37; 'moment,': 0.38; 'some': 0.38; 'think': 0.38; 'received:192': 0.38; 'should': 0.38; "i'd": 0.39; 'point': 0.39; 'why': 0.39; 'subject:: ': 0.39; 'might': 0.40; 'accepts': 0.64; 'harder': 0.64; 'same,': 0.67; 'hate': 0.73; '06:05': 0.84; 'difference.': 0.84; 'hair,': 0.84; 'idiom': 0.84; 'place?': 0.84; 'supporter': 0.91
DKIM-Signature v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=G0BsSNLjf10mJnlKQveABJ3dHoc8MqF3og436ZaDr9k=; b=kvAZLGdO3mu8ajjYVrOF/MBAZqg5TI2I35brroEaJYhwx0KIk7FQGjjmi65uTvSmJA 7Zg9dK7hbQNbygRkIFBWKnPohUj3sdRmlZXMytY055oBU3Ls3nbY2s7AhzS5gcA45peS 88zLD6JpCu15Z61/SuEvQk9vxFNczVRGEgEqg=
Date Mon, 23 Jan 2012 20:50:11 +0000
From Andrea Crotti <andrea.crotti.0@gmail.com>
User-Agent Mozilla/5.0 (X11; Linux x86_64; rv:9.0) Gecko/20111224 Thunderbird/9.0.1
MIME-Version 1.0
To Evan Driscoll <edriscoll@wisc.edu>
Subject Re: while True or while 1
References <4F1AC1D4.2080402@gmail.com> <mailman.4909.1327157944.27778.python-list@python.org> <pL-dnUjq2eH3t4bSnZ2dnUVZ5vudnZ2d@giganews.com> <CAFYqXL8PPOi2dy7M0ae+zCVB2yD6hPDdr7q8MhL0waadqoWvuw@mail.gmail.com> <CALwzidm5NvdqCjrSTap2BE_mrgK9BjK7FEeGAM_cX=BDMKMrzQ@mail.gmail.com> <4F1DA186.1040807@wisc.edu>
In-Reply-To <4F1DA186.1040807@wisc.edu>
Content-Type text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding 7bit
Cc python-list@python.org
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.12
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <http://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.4983.1327351819.27778.python-list@python.org> (permalink)
Lines 39
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1327351819 news.xs4all.nl 6918 [2001:888:2000:d::a6]:41372
X-Complaints-To abuse@xs4all.nl
Xref x330-a1.tempe.blueboxinc.net comp.lang.python:19286

Show key headers only | View raw


On 01/23/2012 06:05 PM, Evan Driscoll wrote:
>
> To play devil's advocate for a moment, if you have the choice between 
> two ways of writing something, A and B, where both are basically the 
> same in terms of difficulty to write, difficulty to maintain, and 
> difficulty to understand, but A is faster than B, even if just by a 
> hair, why NOT write A?
>
> It's like 'iter++' vs '++iter' in a C++ for loop. For ints, or for 
> some iterators with optimization, it makes no difference. But the 
> latter will be faster in debug builds, and *might* be faster in 
> release builds if you have a complicated iterator. So why NOT make 
> for(...; ...; ++i) the typical way of writing a for loop?
>
> In the Python world, is 'while 1' any harder to understand than 'while 
> True'? I'm about as staunch a supporter as you'll find for the idea 
> that 'while 1' should throw an exception, and even *I* think that 
> 'while 1' is about the least-offensive idiom out there. If 'while 1' 
> throws you off, I'd hate to see what you do when you learn that Python 
> accepts loops like 'while x' where the condition evaluates to true if 
> x is a non-zero integer and false if x is 0.
>
>
> All that said, I like the 'while "stuff to do"' idea.
>
> Evan

I think it's not the same, iter++ or ++iter is exactly the same in terms 
of readability, so of course
if one might be a bit faster, it should be used.

while 1 works because the 1 is converted to boolean automatically, but 
why not just writing a boolean
in the first place?

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 
at least
adds some value *and* it might be very slightly faster too.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Re: while True or while 1 Chris Angelico <rosuav@gmail.com> - 2012-01-22 01:59 +1100
  Re: while True or while 1 Erik Max Francis <max@alcyone.com> - 2012-01-21 13:13 -0800
    Re: while True or while 1 Chris Angelico <rosuav@gmail.com> - 2012-01-22 09:13 +1100
      Re: while True or while 1 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-22 05:25 +0000
        Re: while True or while 1 Dan Sommers <dan@tombstonezero.net> - 2012-01-22 16:05 +0000
          Re: while True or while 1 alex23 <wuwei23@gmail.com> - 2012-01-22 19:55 -0800
            Re: while True or while 1 Dave Angel <d@davea.name> - 2012-01-23 08:02 -0500
              Re: while True or while 1 Hrvoje Niksic <hniksic@xemacs.org> - 2012-01-23 14:28 +0100
                Re: while True or while 1 Dave Angel <d@davea.name> - 2012-01-23 13:33 -0500
        Re: while True or while 1 MRAB <python@mrabarnett.plus.com> - 2012-01-22 16:13 +0000
    Re: while True or while 1 Grant Edwards <invalid@invalid.invalid> - 2012-01-23 15:51 +0000
    Re: while True or while 1 Giampaolo Rodolà <g.rodola@gmail.com> - 2012-01-23 17:41 +0100
      Re: while True or while 1 Erik Max Francis <max@alcyone.com> - 2012-01-23 11:12 -0800
        Re: while True or while 1 Giampaolo Rodolà <g.rodola@gmail.com> - 2012-01-23 21:20 +0100
    Re: while True or while 1 Ian Kelly <ian.g.kelly@gmail.com> - 2012-01-23 10:39 -0700
    Re: while True or while 1 Evan Driscoll <edriscoll@wisc.edu> - 2012-01-23 12:05 -0600
    Re: while True or while 1 Andrea Crotti <andrea.crotti.0@gmail.com> - 2012-01-23 20:50 +0000
      Re: while True or while 1 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 14:42 -0800
      Re: while True or while 1 88888 Dihedral <dihedral88888@googlemail.com> - 2012-01-23 14:42 -0800
      Re: while True or while 1 Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2012-01-24 03:37 +0000

csiph-web