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

Re: The beauty of MMD

by jdporter (Paladin)
on Jul 28, 2005 at 18:31 UTC ( [id://479078]=note: print w/replies, xml ) Need Help??


in reply to The beauty of MMD
in thread Perl 5's greatest limitation is...?

Let's play with the wording a bit and see if we can clear that up, shall we?
If we're going to play that game, I'll have a go:
... when it's necessary, it simplifies the code and is a better solution ...

Seems to me that in cases where it's necessary, it doesn't just simplify the code and make a better solution — it makes a solution (and the code) possible. That's what "necessary" means.

More to the point, you completely ignored the part where tilly said (and which I second):

To be convinced I'd need to see a problem which interests me that I have trouble solving without MMD, which has a very nice solution using MMD ...

(Aside: why did you call tilly "Ben"? Seems to me that is just making the argument unnecessarily personal — sort of a virtual "grabbing your opponent by the lapels".)

But anyway...

MMD potentially allows compiler optimizations that aren't possible when dealing with all of the potentially buggy programmer alternatives.
What compiler optimizations are you thinking of? Seems to me there are precious few possible compiler optimizations in dynamic languages relative to their static brethren.
$object->process($foo, $data1, $data2);
Oopsie. The code silently fails.

That is an argument for prototypes on methods, not for MMD specifically.

This is a debate that regularly comes up in the Perl community: how much sanity checking is required?

I fall in the camp that believes perl should stay out of my way unless and until I ask otherwise. Perl is not a B&D language. Strict is off by default.

Replies are listed 'Best First'.
Re^2: The beauty of MMD
by Ovid (Cardinal) on Jul 28, 2005 at 19:23 UTC

    First, I called him "Ben" without thinking about it. He happens to be a friend of mine, we talk on the phone and calling him Ben seems to be natural. It wasn't intended as making thing "personal."

    As for the rest of your points, argue them with Dan Sugalski :) Incidentally, that link points to a concrete example of something that might satisfy tilly's desire to see a problem for which MMD is suitable.

    Oopsie. The code silently fails.

    That is an argument for prototypes on methods, not for MMD specifically.

    As I pointed out earlier in my post, my discussion was about both MMD and proper argument handling. To my mind, you can't have the former without the latter. And I agree with your concerns about B&D. I, too, don't like B&D, but to my point of view, properly implemented MMD could let me having sanity checking without forcing any sort of B&D. See Perl 6's ideas behind MMD for examples.

    Cheers,
    Ovid

    New address of my CGI Course.

Re^2: The beauty of MMD
by eric256 (Parson) on Jul 28, 2005 at 19:25 UTC

    Jumping into a fray that isn't mine:

    I think that the point is MMD is usefull and would be nice to have. I'm not sure what your argument agianst that was except that you didn't like his argument. So here is a plain as day example using Perl6 MMD and i'd like to see your example of the same code that is at least as simple.

    multi method name () { return $.name }; multi method name (Str $new_name) { $.name = $new_name; $new_name };

    The return value of the second call is always debatable, but not realy the point here. This is obviously a very simple example, but the point is, anytime your action varies depending on the types of paramters, MMD is a nice trick to have available. BTW Perl6 allows MMD and allows you to still have your old fashion perl5 send me everything in @_ subs too, so you can have your cake and eat it too (whatever that means ;) )


    ___________
    Eric Hodges
      Here is a Perl 5 example that is simpler than what you provided, even without the Perl 6 syntactic sugar:
      sub get_name {$_[0]{name}} sub set_name {$_[0]{name} = $_[1]}
      And in Ruby it is simpler still:
      attr_accessor :name; # creates name and name= methods for you
      The one thing that my examples are missing which yours provides is a check that the accessor really wants a string. This check is not something that I personally value, but YMMV.

        If you change the problem then yes that is an answer. The point of MMD is one name for a sub that acts differently based upon inputs. The original question was over perl 5 being limited by not having MMD. Which it can be made to do, but your post does not. You may claim that MMD is useless to you, and that is fine, however it makes some tasks quite simple like shown in my post. Your answer is fine and it is probably arguable that any use of MMD can be reformated so that it can be solved without MMD. The same is true for OO, and probably any other single peice of programming or concept, it is however not realy a sound argument agianst anything at all.


        ___________
        Eric Hodges
      Off-topic comment on "have your cake and eat it too" below.
      A reply falls below the community's threshold of quality. You may see it by logging in.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (4)
As of 2024-04-25 05:01 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found