Multiple dispatch again

John Roth johnroth at ameritech.net
Fri Jan 3 21:12:31 EST 2003


"David Mertz" <mertz at gnosis.cx> wrote in message
news:mailman.1041492423.21345.python-list at python.org...
> I've got to thinking about multimethods/multiple dispatch lately.  I
> wonder if Pythonistas have some futher opinions on the use of these.
> Actually, part of it is that I'd -really- like to better understand
use
> cases for multiple dispatch.  As a trick, I can see it has a certain
> elegance, but little rock/paper/scissors toys are not, finally,
> compelling.

If I understand what you're talking about, multiple dispatch is
simply another name for method overloading - or is it?

The only use cases I've seen that are at all compelling for
method overloading fall into the pattern of eliminating
type tests on parameters - that is, let the compiler figure
out what method to invoke based on the parameter types.

In statically typed languages, I've seen any number of applications
of that, and properly used, they make programs much easier to
read than either having to create special names for the different
methods, or having to put a nest of type tests and special case
code in one method.

As far as arcane discussions of exactly how to mix this
with multiple inheritance hierarchies, I'm all in favor of the old
"parenthesis rule:" when there's any possible doubt about the
precedence, add parenthesis. If I have to think about the class
hierarchy to figure out what method overloading is going to do
in a particular case, I don't want to do it. Maintainable code is
blatently obvious code.

John Roth








More information about the Python-list mailing list