[Bioperl-l] Feature/Annotation rollback finished

Chris Fields cjfields at uiuc.edu
Wed Aug 29 23:54:05 EDT 2007


On Aug 29, 2007, at 10:44 PM, Florent Angly wrote:

> Hilmar Lapp wrote:
>> Keep in mind that code such as
>>
>> 	if ($ann) { ... }
>>
>> is mostly not b/c someone wanted to use overloading, but rather   
>> someone was lazy and really meant to say
>>
>> 	if (defined($ann)) { ... }
>>
>> In the absence of eq overloading, these will behave identically.  
>> So  if you leave the exceptions in it is sort-of policing lazy   
>> programmers, which I guess is fine in principle, but is guaranteed  
>> to  trip up a lot of script code. I'd take it out if you're  
>> reasonably  sure that at least within BioPerl itself those lazy  
>> programming  incidents are removed.
> 	if ($ann) { ... }
>
> and
> 	if (defined($ann)) { ... }
>
> are not the same.
>
> 	if ($ann)
>
> is evaluated false for an empty string like
>
>        $ann = '';
>
> and for a value of zero, i.e.
>
> 	$ann = 0;
>
> while
>
> 	defined($ann)
>
> returns true in these 2 cases.
>
> Florent

I agree, but we're talking about the context in which this test is  
performed, where $ann is either an instance of a Bio::AnnotationI or  
undef (not a scalar value or '').  In this case it works both as 'if  
($ann)' or 'if (defined($ann))', though the latter is preferred.   
Never underestimate laziness!

chris


More information about the Bioperl-l mailing list