On Fri, 2 Nov 2001, Matt Sergeant wrote:

> Personaly this whole section stinks. People use different methods, but for
> me, I try and avoid direct @_ access unless absolutely necessary. For
> method calls I prefer:
>
>   my $self = shift;
>   my ($param1, $param2) = @_;
>
> or alternatively:
>
>   my $self = shift;
>   my %params = @_; # I like key/value pairs.

Or even better:

 my $self = shift;
 my %params = validate( @_, { ... } );

using Params::Validate, which will handle defaults and all that goodness.

There's also Raphael Manfredi's Getargs::Long, Benjamin Franz's
Class::NamedParms & Class::ParmList, and James Duncan's
Attribute::Signature (which requires 5.6.0 though).

[ with my own module, that makes at least 4 wheels.  Whee, a car! ]

> I also like to validate params if I'm being uber-strict. Which I don't
> tend to be for CPAN modules, but I do for work-oriented modules. I tend to
> use a derivative of some of D.Rolsky's code that he wrote while we were
> working together (Dave's good at that sort of thing, being as anal as he
> is :-)

I think for P5EE we can justify being super strict.  I use
Params::Validate extensively in Alzabo and its definitely helped me catch
coding errors quicker.

I'd definitely suggest that we add to the style guide that all publicly
available APIs should do argument validation.  I don't know if this is a
style thing so much as a code quality thing.

Anyway, regardless of what validation implementation we come up with I'm
all for having one be required.


-dave

/*==================
www.urth.org
We await the New Sun
==================*/

Reply via email to