I've gone back and forth a few times recently on my Perl coding style when it comes to module subroutines. If you have an object and you want to call the method bar
with no arguments, then you can either do $foo->bar()
or $foo->bar
. At one point I started favoring the latter because I felt it cleaned up the code and made it more readable. However, sometimes I question whether it would be better to be fully explicit, especially considering the possibility that someone else will have to look at my code later — someone who almost certainly will not be an expert Perl programmer.
For example, consider this block of code. For the method calls that require arguments (get_tag_values
and has_tag
), there is no question about the parentheses. But what about next_feature
and primary_tag
? Is the readability I gain from dropping the parens worth losing the explicit syntax? Is one better than the other for long term maintainability? Or is this simply a subjective judgment call?
while( my $feature = $gff3->next_feature )
{
if($type eq "cds")
{
if( $feature->primary_tag eq "mRNA" )
{
my($gene_id) = $feature->get_tag_values("Parent");
my($mRNA_id) = $feature->get_tag_values("ID");
next unless( $list eq '' or $genes_to_extract->{$gene_id} );
$subseq_locations->{ $feature->seq_id }->{ $mRNA_id } = Bio::Location::Split->new();
}
elsif( $feature->primary_tag eq "CDS" )
{
my($mRNA_id) = $feature->get_tag_values("Parent");
if( $subseq_locations->{ $feature->seq_id }->{ $mRNA_id } )
{
$subseq_locations->{ $feature->seq_id }->{ $mRNA_id }->add_sub_Location( $feature->location );
}
}
}
else
{
if( $feature->primary_tag eq $type )
{
my $feat_id;
if( $list ne '')
{
($feat_id) = $feature->get_tag_values("ID") if($feature->has_tag("ID"));
next unless( $feature->has_tag("ID") and $genes_to_extract->{$feat_id} );
}
$subseq_locations->{ $feature->seq_id }->{ $feat_id } = Bio::Location::Split->new();
$subseq_locations->{ $feature->seq_id }->{ $feat_id }->add_sub_Location( $feature->location );
}
}
}