[Bioperl-l] method naming

Chris Fields cjfields at uiuc.edu
Wed Jun 13 14:43:41 EDT 2007


On Jun 13, 2007, at 1:27 PM, Michael Kiwala wrote:

>
> David Messina wrote:
>>> 1) Is there any preference on how to name a method that returns a
>>> list of class instances vs. data?  I have seen  
>>> 'each' (each_Location,
>>> each_tag_value) vs. 'get_all' (get_all_tags, get_all_SeqFeatures)  
>>> vs.
>>> simple (hits, hsps).
>>>
>>
>> I'd prefer 'get_all' because it's more intuitive to me what the   
>> method is doing. 'Each' is too programmer-y.
>>
>>
>>
> When I think 'get_all', I think of a method that returns a list of  
> objects at once. When I think of 'each', I think of a method that  
> returns a scalar but can be called multiple times to iterate over a  
> set of objects.

Yep, hence the ambiguity issue (and my confusion).  I think it was so  
you could both iterate and return a list using this:

for my $obj ($seq->each_Class) {...}
my @objs = $seq->each_Class;

I use 'next' and 'get/get_all' as an iterator and get accessor  
(similar to how it's used in Bio::SearchIO):

while (my $obj = $seq->next_Class) {...}
my @objs = $seq->get_Class; # or get_all_Class for flattened lists

which to me is much clearer.

chris


More information about the Bioperl-l mailing list