[Bioperl-l] argument checking

Aaron J. Mackey amackey at pcbi.upenn.edu
Fri Oct 1 08:09:18 EDT 2004


This idea is an aspect of programming by contract; greatly useful while 
debugging, but needs a way to be turned off *completely* in production 
code (i.e. not just check_args immediately returning success, but 
check_args not even being a part of the call stack) to not make our 
speed problems even worse.

Hmm, I guess you mean to replace existing code that already does the 
same and incurs the same penalty ... I'd argue that the "specification" 
should only be listed once, and the call to _rearrange is probably a 
good place for it to happen, i.e.:

sub foobar {
   my $self = shift;
   my ($doodad, $entries) =
     $self->process_arguments(
       [qw(DOODAD ENTRIES)],                # usual _rearrange argument
       [qw(Bio::Seq::Doodad ARRAY)],        # variable "isa" 
specification
       # override default error messages, with keyword replacement:
       ["Come on, gimme a Doodad, not a [#REF#]!", undef],
     );
   # ...
}

If we did something like this, then process_arguments() could turn into 
the more simpler _rearrange when in production (controlled via ?? - 
lots of options here).  This could be done with source filter trickery 
or the "optimizer" module for maximum benefit.

-Aaron

On Oct 1, 2004, at 6:08 AM, Richard Adams wrote:

> I was wondering what developers thought about a generic argument 
> checking method, say in Bio::Root::Root.
> Obviously the world has continued turning without it since BioPerl's 
> inception but it might
> save  quite few lines of code throughout the whole package.
> What I'm thinking of is
>
> e.g., in usage
> sub x {
> my ($self, $arg1, $arg2) = @_;
> $self->check_args('Bio::SeqI' => $arg1,
>                                'array',       => $arg2);
> ##.. rest of method
> }
>
> Apologies if there is this functionality lurking somewhere and I've 
> not found it yet.
>
> Richard
>
> -- 
> Dr Richard Adams
> Psychiatric Genetics Group,
> Medical Genetics,
> Molecular Medicine Centre,
> Western General Hospital,
> Crewe Rd West,
> Edinburgh UK
> EH4 2XU
>
> Tel: 44 131 651 1084
> richard.adams at ed.ac.uk
>
>
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at portal.open-bio.org
> http://portal.open-bio.org/mailman/listinfo/bioperl-l
>
>
--
Aaron J. Mackey, Ph.D.
Dept. of Biology, Goddard 212
University of Pennsylvania       email:  amackey at pcbi.upenn.edu
415 S. University Avenue         office: 215-898-1205
Philadelphia, PA  19104-6017     fax:    215-746-6697



More information about the Bioperl-l mailing list