[Bioperl-l] Small changes to some Annotation methods?

Lincoln Stein lstein at cshl.edu
Wed Jan 21 01:51:21 EST 2004


Hi,

You should do this:

	return unless $self->{'_names'};

rather than

	return undef unless $self->{'_names'};

if you explicitly return undef, then someone who calls the method in a 
list context:

	my @genes = $foo->each_gene_name;

Will end up with a one-element array in which the element is the value 
undef.

Lincoln
	
On Wednesday 21 January 2004 07:38 am, Hilmar Lapp wrote:
> The array property should be initialized to an empty array upon
> object construction. Returning undef from an array accessor is not
> good, you may break people's code.
>
> Which object are you talking about? Does the respective class not
> initialize the property to be an empty array?
>
> 	-hilmar
>
> On Tuesday, January 20, 2004, at 10:20  AM, Stefan Kirov wrote:
> > Can we change the accessor methods, for example:
> > sub each_gene_name{
> >   my ($self, at args) = @_;
> >
> >   return @{$self->{'_names'}};
> > }
> > to
> > sub each_gene_name{
> >   my ($self, at args) = @_;
> >   return undef unless ($self->{'_names'});
> >   return @{$self->{'_names'}};
> > }
> > The current implementation will break the code if  return
> > @{$self->{'_names'}} is empty.
> > Jason, Heikki- I am asking just in case I am missing
> > something....
> >
> > Stefan
> >
> > _______________________________________________
> > Bioperl-l mailing list
> > Bioperl-l at portal.open-bio.org
> > http://portal.open-bio.org/mailman/listinfo/bioperl-l

-- 
Lincoln D. Stein
Cold Spring Harbor Laboratory
1 Bungtown Road
Cold Spring Harbor, NY 11724


More information about the Bioperl-l mailing list