Tuesday, November 08, 2005

Python Equality, Comparison, and Hashing

There has been a lot of talk on python-dev about the behavior of the default __eq__ and __hash__ and the comparison of objects, specifically with the concepts of "Identity Objects" and "Value Objects".

This brings me to think about something I've pondered, and I'm sure has been discussed before: does a programming langauge have to compare apples and oranges? Perhaps it is a historical artifact that everything can be compared. When everything is just a representation of byte patterns, everything can be compared numerically, but this doesn't always make sense for what is being compared. Boolean logic is tied into nearly every computer langauge, so that everything can be considered true or false. Well, what about raising an exception on 1=="1" instead of just resolving to False? How about denying a conversion of an object to true or false, where it has no logical boolean equivalent?

Why does everything have to boil down to black or white?

1 comment:

123 123 said...

Cool story as for me. It would be great to read a bit more concerning that matter. Thanks for sharing this information.
Sexy Lady
UK escorts