[Python-ideas] Smallest/Largest singletons

Scott Dial scott+python-ideas at scottdial.com
Mon Nov 17 03:21:43 CET 2008


George Sakkis wrote:
>> Using special objects to be lazy with your algorithm will never be
>> wise.
> 
> s/lazy/elegant

To each his own, but your substitution fails to convince me that magic
values are more readable than using a "valid" flag variable.

>> -1 Let's not provide features for misguided programming idioms.
> 
> I don't consider Dijkstra's shortest path algorithm and the others
> mentioned in PEP 326 as examples of misguided programming idioms.

The algorithm isn't misguided. The use of a magic constant is misguided.
Please don't confuse the language I choose. The only way it's safe is if
you if-check the output values from your algorithm, and then there is no
reason to have a special value, just use a flag. If you are not doing
the if-check, then you are using a misguided programming idiom (unless
you have proven for all possible inputs, there is a solution to your
algorithm.) While in the examples in PEP 326, it's vaguely clear that
it's not a problem. I imagine many uses that behave like this:

minval = Max
for i in vals:
    if i < minval:
        minval = i

Which is a failure of design championed by a programming idiom you want
to create. At least, if they attempt to pick some "Max" value, they will
have the opportunity to realize the mistake rather than assume "it's the
Python way". Furthermore, the PEP's examples aren't compelling because
you can roll-your-own easily if you want such a thing, and since I
consider it strictly bad to use them as output values, it makes no
difference if its a built-in or not.

> Besides, the reasons for rejection read more
> like a lukewarm -0 ("not that useful, easily implemented, can't decide

Perhaps, but I for one think it's silly.

-Scott

-- 
Scott Dial
scott at scottdial.com
scodial at cs.indiana.edu



More information about the Python-ideas mailing list