[Bioperl-l] issues with _rearrange

Aaron J Mackey Aaron J. Mackey" <amackey@virginia.edu
Thu, 19 Sep 2002 08:29:23 -0400 (EDT)


In exploring how we might better handle billions of calls to _rearrange,
I've discovered something a little disturbing: there are many places in
our code where we completely assume that @args is actually a hash, and add
to the hash:

# in Bio::Seq::SeqFactory
sub create {
   my ($self,@args) = @_;
   return $self->type->new(-verbose => $self->verbose, @args);
}

But what if I had use the "flat" argument construction type?  Now my
arguments don't work anymore, because _rearrange will see -verbose and
assume the rest is a hash.

Now, in fact, this doesn't seem to happen in any of our test cases; why?
It's because *no one actually uses an array of flat arguments* (or at
least not when interacting with code such as above).  If we agree that
we're going to *require* hashes of options, then _rearrange becomes much
simpler (and in fact, can be replaced entirely):

my ($self, @args) = @_;
my ($a1, $a2, $a3) = $self->_rearrange([qw(a1 a2 a3)], @args);

becomes:

my ($self, %args) = @_;
my ($a1, $a2, $a3) = @args{qw(a1 a2 a3)};


On the other hand, if we argue that we must continue to accept flat arrays
of arguments, then we must begin to fix code like that seen above; now
Bio::Seq::SeqFactory::create() becomes:

sub create {
   my ($self,@args) = @_;

   # lots of code to inspect @args for hash keys or not; if it is a
   # flat array, need to figure out how many arguments were provided, and
   # where "verbose" should fit in; this requires knowing what
   # $self->type->new() is going to expect to see ... yet more overhead
   # here to come ...

   return $self->type->new(@args);
}

Something to think about ...

-Aaron

-- 
 Aaron J Mackey
 Pearson Laboratory
 University of Virginia
 (434) 924-2821
 amackey@virginia.edu