Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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.


In reply to Re^2: Use method/function signatures with Perl by Ovid
in thread Use method/function signatures with Perl by Ovid

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (3)
As of 2024-04-24 23:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found