Rich Comparisons Gotcha

Mark Dickinson dickinsm at gmail.com
Sun Dec 7 19:14:06 CET 2008


On Dec 7, 4:23 pm, Rasmus Fogh <rh... at mole.bio.cam.ac.uk> wrote:

> If is is possible to change the language, how about having two
> diferent functions, one for overloading the '==' operator, and another
> for testing list and set membership, dictionary key identity, etc.?

I've often thought that this would have made a lot of sense too,
though
I'd probably choose to spell the well-behaved structural equality "=="
and the flexible numeric equality "eq" (a la Fortran).  Hey, we could
have *six* new keywords: eq, ne, le, lt, ge, gt!

See the recent (September?) thread "Comparing float and decimal"
for some of the fun that results from lack of transitivity of
equality.

But I think there's essentially no chance of Python changing to
support this.  And even if there were, Python's conflation of
structural equality with numeric equality brings significant
benefits in terms of readability of code, ease of learning,
and general friendliness; it's only really troublesome in
a few corner cases.  Is the tradeoff worth it?

So for me, this comes down to a case of 'practicality beats purity'.

Mark



More information about the Python-list mailing list