in reply to Re: Object method prototypes?
in thread Object method prototypes?

I like named parameters, but I don't like hashrefs. (update: for parameter passing, I mean)

When I need more than 2 or so parameters I tend to use this construct:

sub my_method { my ($self,%args) = @_; # now do stuff with $self and %args } # which is called as $object->my_method( foo => $value, bar => $bee );
Saves typing and IMHO is nicer to look at at both sides.

Replies are listed 'Best First'.
Re^3: Object method prototypes?
by Puny Human (Initiate) on Dec 14, 2007 at 01:39 UTC
    That works, as long as you don't mind creating and destroying an argument hash every time your method is called. Passing a hashref would avoid that, but unless you're writing performance-sensitive code it doesn't matter much.
      what's worse than copying the hash is having the called method (or another it calls) impolitely muck with your hashref by deleting or adding keys for its own purposes.

      next thing you know, you find yourself making a copy anyway so you can send an anon ref to that instead..

      I personally believe that passing a hashref would also create and destroy a hash every time your method is called. Additionally, it would take a reference to it. So the performance-sensitive comment is completely moot.

      --
      If you can't understand the incipit, then please check the IPB Campaign.