in reply to Re^2: Prototype for constant items???
in thread Prototype for constant items???
Checking the parameters with ref is good.
Wherever it makes sense, I like to have the function detect that you've passed in an arrayref instead of a simple scalar, and then call itself foreach (@$param). Same with hashes. Lets you munge entire trees of values in one go, in a DWIM sort of way.
Wherever that doesn't make sense, use croak and explain why the parameter is bad. You're not even limited to just "type". You can throw useful errors about much more subtle problems: "Temperature parameter cannot be less than absolute zero in call to set_thermostat() at monkey.pl line 42". Detailed and specific explanations of what went wrong are good.
Don't limit yourself to prototypes, they rarely help. Just put in some good old preconditions with plain text explanations of what the caller did wrong.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: Prototype for constant items???
by LanX (Saint) on Sep 25, 2009 at 14:55 UTC | |
by SuicideJunkie (Vicar) on Sep 25, 2009 at 16:34 UTC | |
by LanX (Saint) on Sep 26, 2009 at 00:48 UTC | |
by SuicideJunkie (Vicar) on Sep 28, 2009 at 13:53 UTC | |
by Porculus (Hermit) on Sep 26, 2009 at 17:37 UTC | |
by LanX (Saint) on Sep 26, 2009 at 20:17 UTC |