Apologies if I've missed some earlier discussions on multimethods.  The
apocolypses, exegesises and synopses don't seem to say much other than
(a) they will exist and (b) wait for apocolypse 12 for more information.

Looking over RFC 256[*] and Class::Multimethods[**] it sounds like the
intent is to implement method overloading similar to C++/Java or
multimethods in CLOS in a Perlish fashion.  Dan's WTHI MMD[***] has also
been quite helpful.

I'm paging through "The Art of the Metaobject Protocol" for bedtime reading
material, and multimethods are starting to give me a big case of The Fear.


As I understand it, the idea behind MMD is that languages like C already
do it with basic operators, since '5 + 3' generates different instructions
than '5 + 3.1' or '5.5 + 3.1' do.  But weak languages like C do not allow
that mechanism to be triggered by user defined functions.  The obvious
answer in type heavy languages like C++, Java or Common Lisp is to extend
that behavior for user defined functions.

Somehow that just feels wrong in Perl.  In all of the Perl code I've
written, I've *never* felt the need to overload the + operator, or have
one of five possible implementations of new() automagically selected by
the datatypes of its arguments.  Furthermore, most Perl programs I've read
or written aren't very type heavy -- there's still a lot of text slinging
and plain vanilla reference processing going on, and presumably that will
still be the case in five years' time.

Type-based MMD as it exists elsewhere are solving a problem that does not
exist in Perl, or at least does not exist to the same extent it does in
other languages.  Similarly, value-based dispatching is dirt simple in
Perl and easy to implement that it's an idiom that at least I use
constantly.


Add all that up, and MMD is a lot of pain for not a huge benefit.  Not
because MMD is a necessarily bad idea, but because MMD doesn't go *far*
enough, since it's limited to type signatures.

A better fitting solution wouldn't focus on classic MMD, but simply
"Dispatch", where type- and value-based dispatching are two of many kinds
of dispatching supported.  If there's a third kind of dispatching (e.g.
a hybrid model), then the dispatching machinery would be open enough for
someone to write a new dispatcher class in Perl instead of warping the
language.

I haven't been following language syntax discussions recently, so I'll
refrain from proposing a straw man.

Z.

*:   http://dev.perl.org/rfc/256.pod
**:  http://search.cpan.org/author/DCONWAY/Class-Multimethods-1.70
***: http://www.sidhe.org/~dan/blog/archives/000194.html

Reply via email to