[Python-Dev] Re: PEP 326 now online

Phillip J. Eby pje at telecommunity.com
Mon Jan 5 09:19:43 EST 2004


At 12:00 AM 1/5/04 -0500, Terry Reedy wrote:

>I do believe that it would be useful (and arguably justifiable) to have a
>built-in coordinated pair of hi/lo, top/bottom objects *separate* from
>None.  To avoid adding builtin names, they could be bound to cmp as the
>attributes cmp.hi and cmp.lo.  It would be almost obvious, and trivial to
>remember, that these are objects that compare hi and lo respectively.  They
>could be instances of object, NoneType, or maybe a new CompType.  Their
>string representations could be ObjHi/ObjLo, NoneHi/NoneLo (if of type
>object or NoneType), or maybe Highest and Lowest.

I'm somewhere between -0 and +0 on the above, so split the difference and 
call it 0.   :)


>Since these two objects would function as identities for comparison, I
>would make them the default start values for max and min reductions, so
>that max() = max([]) = Highest and  min() = min([]) = Lowest, instead of
>raising exceptions, just as sum([]) = 0.  This is, however, an optional
>part of this suggestion.

-1 on changing the exception throwing behavior; it would make bugs in 
programs that aren't expecting these objects harder to find (i.e., because 
later operations will fail instead of the min or max call).



>"For example, in Dijkstra's shortest path problem on weighted edges, one
>starts out by setting the distances of everything in the graph to
>infinity, setting the starting point distance to zero, then
>systematically pulling out the node with smallest distance, adding its
>neighbors, etc.  Min and max are arbitrarily limiting, which is why they
>aren't used."

I always thought the natural way to do this was to have a stack (heap) of 
nodes to be checked, initialized with the starting node, and an initially 
empty map of node:distance.  Setting distances to infinity seems very 
artificial to me, given that what's actually meant is that the distance is 
*unknown*.  But maybe that's just me.  IMO, as we live in a finite reality, 
infinity doesn't come up that often as a referent in software.  Unless of 
course you're doing mathematics, which in its most perfected forms has 
nothing to do with the real world.  ;)

But if you are doing mathematics, then the infinity ought to have the 
numeric properties of infinity, shouldn't it?  For example, adding, 
multiplying, subtracting from, or dividing infinity ought to still produce 
infinity, no?  This is why I keep saying that having more concrete use 
cases would be better, and am only "0" on the cmp.hi/lo or Highest/Lowest 
objects.




More information about the Python-Dev mailing list