Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
Syntactic Confectionery Delight
 
PerlMonks  

Re^4: Preferred technique for named subroutine parameters?

by akho (Hermit)
on May 22, 2009 at 20:47 UTC ( #765746=note: print w/ replies, xml ) Need Help??


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

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.


Comment on Re^4: Preferred technique for named subroutine parameters?
Re^5: Preferred technique for named subroutine parameters?
by AnomalousMonk (Monsignor) on May 22, 2009 at 22:16 UTC
    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
Node Status?
node history
Node Type: note [id://765746]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (7)
As of 2014-04-21 12:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (495 votes), past polls