[Bioperl-l] best coding practices

Jason Stajich jason at cgt.duhs.duke.edu
Thu Jul 3 09:19:03 EDT 2003



> If you delegate to a method, *always* use the following style or
> something similar. It is safe regardless in which style the delegation
> target is implemented. It is also forward compatible if the method to
> which you delegate will ever expect or deal with more than just one
> argument (or change to named parameters for that matter).
>
> sub some_derived_property{
> 	my $self = shift;
> 	# this is the Right Way to delegate: @_ is an empty array if exhausted
> after
> 	# pulling off $self, not an undefined but present argument
> 	return $self->some_property(@_);
> }
>
> I had to clean up a couple of methods in Bio::Search::HSP::HSPI and it
> took me quite a while to track down the offender (BTW HSPI does a bit
> more than just decorating implementations ...).

It only uses methods that are part of HSPI and do not do any direct
storage of data which would make an assumption about the underlying
object.

>
> I don't know whose coding style using blabla(shift) for delegation is,
> but Steve or Jason please when you get a chance it'd be great if you go
> through all of those Search modules where this applies. Every such call
> is a lurking bug waiting to be triggered by changing the underlying
> implementation of the delegation target.
>

This was from Tim Bunce proposed as the most efficient way to do things.
I think there are problems in some of the SeqFeature objects as well that
I had found before wrt mixing the styles of getter/setters but I had
trouble reproducing it.

> 	-hilmar
>
>

--
Jason Stajich
Duke University
jason at cgt.mc.duke.edu


More information about the Bioperl-l mailing list