in reply to passing subroutine args as a hash: why not?

Nit: you don't need the prototype; Perl does the right thing for you automatically.

I like hashes in constructors where I may have to set defaults. They're also nice when you don't want to remember the positions of arguments:

my $alias = Mail::SimpleList::Alias->new( Expires => '7d', Auto_add => 0, Closed => 1, ); # and in Mail::SimpleList::Alias sub new { my $class = shift; bless { Owner => '', Auto_add => 1, Expires => 0, Closed => 0, @_; }, $class; }

Replies are listed 'Best First'.
Re: Re: passing subroutine args as a hash: why not?
by Willard B. Trophy (Hermit) on Jun 05, 2003 at 18:51 UTC
    I know I don't need the % prototype, but it helps those who come after me know what the subroutine expects.

    I'm sure you didn't use the term nit in the way it means where I'm from ...

    --
    bowling trophy thieves, die!

      I know I don't need the % prototype, but it helps those who come after me know what the subroutine expects.

      That's no reason to use a prototype. That's what comments are for. Perl's prototypes aren't really prototypes at all. It's a great irony that so many people use them under the impression that they are making their code more maintainable because using them without knowing exactly when it is OK to use them will do exactly the opposite.

      Prototypes in Perl should be avoided in all but the rarest of cases. See Tom Christiansen's article on them.

      -sauoq
      "My two cents aren't worth a dime.";
      
        So if Perl prototypes are so critically borked, and this was known in 1999 when Tom C wrote the article, why does my 5.8 perlsub documentation from 2002 imply they are a good thing?
        Confusing signals, people ...

        --
        bowling trophy thieves, die!

      I meant nit as in nitpick, which appears to have an etymology related to lice eggs. (Those little circles in the percent sign are a happy accident.)

      I don't understand what you mean by it helps those who come after me know what the subroutine expects. If they're reading the code, why not read the very next line in the function to see exactly how you're dealing with parameters? If they're reading the documentation, you'll have to tell them what to expect anyway.

      I'm all for not repeating myself. I just don't see what the function parameter adds.