[Python-Dev] PEP 326 (quick location possibility)
Aahz
aahz at pythoncraft.com
Thu Jan 29 14:28:22 EST 2004
On Thu, Jan 29, 2004, Tim Peters wrote:
> [Aahz]
>>
>> I'm curious: why you didn't use None as the initial value or use some
>> other hack to avoid initializing with a specific number?
>
> In 2.3, None compares less than anything else; the search loop required that
> the initial value compare larger than anything else (although I wouldn't
> have been comfortable with relying on that None compares smaller either,
> since that's non-obvious version-specific behavior).
>
> I've since tended to write these kinds of loops as:
>
> global_min = None
> ...
>
> if global_min is None or score(candidate) < global_min:
> global_min = score(candidate)
> do stuff appropriate for a new local minimum
That's precisely what I was suggesting, yes.
> but it's easy to forget the "global_min is None" clause -- in which case,
> *because* None compares less than everything else, the "if" test never
> passes.
That's not a problem I've run into, and I don't see it cropping up all
that often on c.l.py. (To be precise, I don't have any memories of it
cropping up.)
--
Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/
"The joy of coding Python should be in seeing short, concise, readable
classes that express a lot of action in a small amount of clear code --
not in reams of trivial code that bores the reader to death." --GvR
More information about the Python-Dev
mailing list