[Python-Dev] PEP 326 (quick location possibility)
Tim Peters
tim.one at comcast.net
Thu Jan 29 11:04:00 EST 2004
[Tim'
>> ...
>> There are few enough bugs in my code at this age that I take very
>> seriously any principled gimmick that could prevent repeating one.
[Raymond]
> Alex Martelli had proposed extending the key= idea to min() and max().
> The idea is to let those functions completely encapsulate the logic
> of searching for minimum and maximum elements:
>
> bestplayer = min(players, key=attrgetter('points'))
>
> This would work equally well with other objective functions.
Different issue. I didn't have "a sequence". The loop was more like:
global_minimum = made_up_value_presumed_to_be_unreachably_large
while mote_to_look_at:
do a ton of computation, yielding a candidate
if score(candidate) < global_minimum:
global_minimum = score(candidate)
do a ton of stuff to prune the search based
on the new (so far) local minimum
return global_minimum
It's picking the made_up_value_presumed_to_be_unreachably_large that's a
brittle hack, and is specifically the source of the bug I mentioned. Adding
new twists to min() wouldn't have made any difference to that.
More information about the Python-Dev
mailing list