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

Sendu Bala sb at mrc-dunn.cam.ac.uk
Thu Jun 1 07:59:21 UTC 2006


Chris Fields wrote:
> 
> Sendu Bala wrote:
>> 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. 

Though if anyone is using that cookie-cutter/macro style, that's much 
worse because now you can't return 0.

return $return_value if defined($return_value);
return;

In any case, it burns the eyes. I share Lincoln's POV. I also fully 
understand your point about not being able to trust the docs 
(Bio::Map::Marker...). But the solution is to change the code so they 
match the docs when the docs make sense, not change the code so that it 
no longer matches the docs[*]. In a massive OO project like bioperl the 
users need to be able to rely on the docs. You can't turn around and say 
"you've used this method for years, but now I'm changing how it works 
because you might have used the method incorrectly". Ideally any code 
changes add functionality or improve it's working without affecting code 
  that uses the method correctly according to its old docs.


* though if there isn't time/interest in changing the code, and the 
method never worked as per the docs, then by all means change the docs 
to avoid confusion - just don't change the docs on a method that worked 
according to the docs, because then you can assume people use the method 
and will be affected by the change



More information about the Bioperl-l mailing list