[Bioperl-l] For CVS developers - potential pitfallwith"returnundef"

Chris Fields cjfields at uiuc.edu
Wed May 31 18:50:30 UTC 2006



> -----Original Message-----
> From: bioperl-l-bounces at lists.open-bio.org [mailto:bioperl-l-
> bounces at lists.open-bio.org] On Behalf Of Sendu Bala
> Sent: Wednesday, May 31, 2006 9:57 AM
> To: bioperl-l at lists.open-bio.org
> Subject: Re: [Bioperl-l] For CVS developers - potential
> pitfallwith"returnundef"
> 
> Heikki Lehvaslaiho wrote:
> > In my opinion the sooner the bugs get exposed the better. It is much
> more
> > likely that there is a well hidden bug caused by assigning accidentally
> undef
> > into an one element array that someone intentionally writing code that
> > expects that behaviour!
> >
> > I removed (but did not commit yet) all undefs from my old Bio::Variation
> code
> > and could not see any differences in the test output.
> >
> > Let's remove them!
> 
> Just looking for all return undef;s isn't enough. It's entirely possible
> to do something like:
> 
> my $return_value;
> {
>    # do something that assigns to return_value on success
>    # on failure, just do nothing
> }
> return $return_value;

Agreed, though looking for these is obviously much harder.  

The way to get around those is:

return $return_value if $return_value;
return;

which I've seen used in a number of get/set methods. 

> The bioperl docs will typically explicitly state that undef is returned,
> and under what circumstance. If a user suffers from the
> undef-into-array-problem, yes it can be slightly unexpected, but lots of
> unexpected things will happen when you don't use a method correctly, as
> per the docs!

Right, but the argument you make is that code will always work as expected
from the perldoc examples.  My recent experiences with the
Bio::Restriction::IO and Bio::Species classes show that the docs are not
always up-to-date and may indicate the unimplemented intent of the author
more than the actual implementation.  Again, I believe a large majority of
the docs are fine, but it's those few errors that made a devil's advocate of
me...

> Fixing the return of undef is either a job that shouldn't be done, or a
> much harder job than expected.

I don't think ignoring the problem is the best answer here though I agree
the problem is more complicated than at first glance.  Judging from code I'm
trolled through a bit lately I've seen a lot of methods (mainly get/setters)
that are essentially copied multiple times in the same or across similar
modules to save time.  You could see a scenario where, in those instances,
so-called 'bad code' would spread quite quickly.

I think adding a wiki page to address some of these issues would be nice,
something separate from the Project Priority List.

Chris
 _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l




More information about the Bioperl-l mailing list