Python from Wise Guy's Viewpoint
Joachim Durchholz
joachim.durchholz at web.de
Mon Oct 20 07:13:45 EDT 2003
Pascal Costanza wrote:
> Joachim Durchholz wrote:
>
>> Oh, you're trolling for an inter-language flame fest...
>> well, anyway:
>>
>>> 3. no multimethods (why? Guido did not know Lisp, so he did not know
>>> about them) You now have to suffer from visitor patterns, etc. like
>>> lowly Java monkeys.
>>
>> Multimethods suck.
>
> Do they suck more or less than the Visitor pattern?
Well, the visitor pattern is worse.
Generics would be better though.
> So how do you implement an equality operator correctly with only single
> dynamic dispatch?
Good question.
In practice, you don't use dispatch, you use some built-in mechanism.
Even more in practice, all equality operators that I have seen tended to
compare more or less than one wanted to have compared, at least for
complicated types with large hidden internal structures, or different
equivalent internal structures. I have seen many cases where people
implemented several equality operators - of course, with different
names, and for most cases, I'm under the impression they weren't even
aware that it was equality that they were implementing :-)
Examples are:
Lisp with its multitude of equality predicates nicely exposes the
problems, and provides a solution.
Various string representations (7-bit Ascii, 8-bit Ascii, various
Unicode flavors). Do you want to compare representations or contents? Do
you need a code table to compare?
Various number representation: do you want to make 1 different from 1.0,
or do you want to have them equal?
I think that dynamic dispatch is an interesting answer, but not to
equality :-)
Regards,
Jo
More information about the Python-list
mailing list