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

If one key gets misspelled, it can create an ugly bug that is hard to find.

This is one of the best reasons to use named parameters! Within your subroutine you can match the names you received against a list of names you expected to receive and you know immediately what's missing. You can also wrap the arguments in a temporary parameter object that automatically does the argument checking for you.


"The dead do not recognize context" -- Kai, Lexx
  • Comment on Re: Re: passing subroutine args as a hash: why not?

Replies are listed 'Best First'.
Re: Re: Re: passing subroutine args as a hash: why not?
by Anonymous Monk on Jun 06, 2003 at 17:36 UTC
    So now you have to add logic to figure out what was misspelled in each subroutine. Talk about overhead.

    sub somethingComplicated() { my( $var1, $var2, $var3, $var4 ) = @_; }
    Calling this and screwing up the assignment to var3 via the function call is quite hard. It's called protecting the developer from shooting himself in the foot.