Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: Use method/function signatures with Perl

by Anonymous Monk
on Dec 06, 2004 at 01:26 UTC ( [id://412558]=note: print w/replies, xml ) Need Help??


in reply to Use method/function signatures with Perl

Maybe I'm braindead today. What didn't you like about Class::Multimethods ?

Replies are listed 'Best First'.
Re^2: Use method/function signatures with Perl
by Ovid (Cardinal) on Dec 06, 2004 at 01:44 UTC

    Several things. Let's compare. Here's some code from the CMM docs:

    multimethod find => (Container, Query) => sub { $_[0]->findquery($_[1]) }; multimethod find => (Container, Sample) => sub { $_[0]->findlike($_[1]) }; multimethod find => (Index, Word) => sub { $_[0]->lookup_word($_[1]) };

    And how would that compare with Sub::Signatures?

    sub find(Container $container, Query $query) } $container->findquery($query); }; sub find(Container $container, Sample $sample) } $container->findlike($sample); }; sub find(Index $index, Word $word) { $index->lookup_word($word) }; }

    Mine is easier to use and a bit more flexible if you merely want to dispatch based on the number of arguments. It's also easier to understand because it looks like just about every other language out there as opposed to the CMM syntax. This means existing code is more easily ported to/from this solution. Also, my code (IMHO) is simpler than Damian's, though he does his without the source filter. I guess it all boils down to the fact that I've never felt comfortable with the interface to CMM.

    Also, my code is more than multi-method dispatch. Just having function signatures is a nice bonus and you can even use them with anonymous subs (in 0.1 and without the MMD.)

    In short, there's nothing wrong with Damian's solution. The major difference in code lies in my trying to solve a problem of a somewhat different scope. At this point, the only significant advantage to his code is the fact that it's been around a lot longer is likely to be more robust as a result. My code quite possibly has serious limitations that I haven't accounted for. That's why I'm looking forward to bug reports :)

    Cheers,
    Ovid

    New address of my CGI Course.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://412558]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (7)
As of 2024-03-28 19:44 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found