Attack a sacred Python Cow
Sebastian "lunar" Wiesner
basti.wiesner at gmx.net
Thu Jul 24 12:02:15 CEST 2008
Jordan <jordanrastrick at gmail.com>:
> # Blog code, not tested
> class A():
> def __eq__(self, obj):
> return True
> a = A()
> b = 
> assert a == b
> assert not (a != b)
> The second assertion fails. Why? Because coding __eq__, the most
> obvious way to make a class have equality based comparisons, buys you
> nothing from the != operator. != isn't (by default) a synonym for the
> negation of == (unlike in, say, every other language ever);
This is just plain wrong for at least C# and C++. C# wants you to
explicitly overload "!=", if you have overloaded "==", C++ complains
about "!=" not being defined for class A. If you had derived A from a
another class in C++, the compiler would happily use the operator from the
base class instead of doing silly aliasing of "!=" to "! ==" ...
> The sad thing is there are plenty of smart Python programmers who will
> justify all kinds of idiocy in the name of their holy crusade against
> the implict.
> If there was one change I could make to Python, it would be to get
> that damn line out of the Zen.
Fortunately, Python isn't designed according to your ideas, and won't
change, so consider your posting a waste of time. If feeling like bringing
such old "issues" up again next time, spend your time learning another
programming language, as you would obviously not get happy with Python
Freedom is always the freedom of dissenters.
More information about the Python-list