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

Re^3: Preferred technique for named subroutine parameters?

by AnomalousMonk (Archbishop)
on May 22, 2009 at 20:43 UTC ( [id://765743]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Preferred technique for named subroutine parameters?
in thread Preferred technique for named subroutine parameters?

But then you have to test,  croak and  carp all over the place. This mitigates against 'clean' code (for some definition of 'clean').

With the anonymous hash approach, don't you get pertinent warnings 'for free'?

Replies are listed 'Best First'.
Re^4: Preferred technique for named subroutine parameters?
by akho (Hermit) on May 22, 2009 at 20:47 UTC
    You have to test that you have the correct number of arguments anyway (in most cases, at least).

    Also: specific error messages are way better than generic ones.

      You have to test that you have the correct number of arguments anyway (in most cases, at least).
      But this is really about parameter validation: required versus optional parameters, acceptable ranges of parameter values, misspelled parameter names, etc. Depending on the situation, validation can be quite simple (or non-existent!) or quite involved. In any case, it is something that can only be handled 'within the function'.

      But again, to me, the question of whether each named parameter has some value associated with it is a question that can be (and is best) handled by default, right there and then at the function call.

      Also: specific error messages are way better than generic ones.
      I tend to agree, but this becomes a matter of individual taste. For myself, a message like  Odd number of elements in anonymous hash at 765727_1.pl line 38. is both sufficiently specific and sufficiently proximate to the point of occurrence – especially if the program died at line 38!

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (4)
As of 2024-04-25 21:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found