Wednesday, August 23, 2006

Python Sprint Notes

We've finished three days of sprinting. I wanted to capture a few brief observations about the sprint. I've got a separate post underway that gets into the details of the source-to-source translation project.

Guido and Alex are working on the removal of the original 3-way compare function. In Python 3000, rich comparisons will be the only available comparison. The other key comparison change, already planned, is that comparison of unlike types will raise an exception by default. (Python 2.x defines an arbitrary total ordering, such that there is some way to sort a list containing numbers, sockets, and code objects.)

The 3-way compare shows up in several places in Python 2.x. The builtin cmp(a, b) function returns a number that indicates whether a is less than, equal to, or greater than b. A class can implement an __cmp__() (and __rcmp__()?) method to define how it compares to other objects. You can also pass a 3-way compare function to list.sort(). Good bye to all of them.

One of the last straws for Alex was this anomaly: When is it true that

   (x != y) and ([x] == [y])

When x and y are NaNs! There's no easy way to fix this anomaly, because of the bits of comparison logic scattered through the interpreter.
>>> [x] == [y]
>>> x == y
>>> x
>>> y
Martin is working on unifying ints and longs. He is taking a perhaps unobvious approach: Remove all the int code and see if the long code can be optimized to make small longs fast enough. An unexpected issue in this work was that bool inherits from int! Martin also changed
bool so that it is no longer a number.


Anonymous said...

I can't reproduce the NaN equality issue here, is it platform dependent? I tried 2.3 and 2.4 on linux.


Jeremy Hylton said...

Yes. The bug is platform dependent. The session I copied was on Windows.