while True or while 1
rosuav at gmail.com
Sat Jan 21 17:13:23 EST 2012
On Sun, Jan 22, 2012 at 8:13 AM, Erik Max Francis <max at alcyone.com> wrote:
> Why this should concern anyone, I don't know; someone who's rebound `True`
> or `False` to evaluate to something other than true and false, respectively,
> is only doing so to be difficult (or very foolish). One of the principles
> of Python programming is that We're All Adults Here, so this kind of
> defensive programming is really superfluous. In other words, yes, it's
> quite reasonable to assume that (even in Python 2) `True` is bound to
> something which is, in fact, true.
Yes, but there's no special code in the compiler to handle True - it's
just a name like any other. It finds a token that looks like a name,
so it puts a name lookup into the bytecode.
> The real reason people still use the `while 1` construct, I would imagine,
> is just inertia or habit, rather than a conscious, defensive decision. If
> it's the latter, it's a case of being _way_ too defensive.
Ehh, 'while 1' is shorter too. I reckon some people are just lazy :)
Or have come from C where 'while (1)' is the normal thing to do.
According to the Eliza Effect, supporting 'while 1' is a Good Thing.
More information about the Python-list