Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #19295
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2012-01-23 14:42 -0800 |
| References | (2 earlier) <pL-dnUjq2eH3t4bSnZ2dnUVZ5vudnZ2d@giganews.com> <CAFYqXL8PPOi2dy7M0ae+zCVB2yD6hPDdr7q8MhL0waadqoWvuw@mail.gmail.com> <CALwzidm5NvdqCjrSTap2BE_mrgK9BjK7FEeGAM_cX=BDMKMrzQ@mail.gmail.com> <4F1DA186.1040807@wisc.edu> <mailman.4983.1327351819.27778.python-list@python.org> |
| Subject | Re: while True or while 1 |
| From | 88888 Dihedral <dihedral88888@googlemail.com> |
| Message-ID | <mailman.4993.1327358527.27778.python-list@python.org> (permalink) |
在 2012年1月24日星期二UTC+8上午4时50分11秒,Andrea Crotti写道: > 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. A fake generator that can't be cascaded for more processing can be called an iterator by the definition of an iterator. But that is miss-leading in implementing silly trivial non-qualified iterators.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll 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