[Bioperl-l] some not-so-good perl practice in bioperl
Juguang Xiao
juguang at tll.org.sg
Mon Dec 22 03:28:59 EST 2003
Hi all,
I was Java programmer learning Perl from Bioperl code. I did learn a
lot for you ushers. Recently, I decide to read Programming Perl, the
Perl Bible, and found some common-sense code in bioperl is not the
best. Here are my findings.
1) getset
Months ago, Hilmar gave us a tip for the getter/setter to accept undef.
The code is like
sub name {
my $self=shift;
return $self->{_name} = shift if @_;
return $self->{_name};
}
It is no fault about it until this super or sub module have a method
with different name but use the same hash key. So choosing the hash
key is not on your own ease. Here is the code in Section 12.7
sub name {
my $self = shift;
my $field = __PACKAGE__ . "::name";
if (@_) { $self->{$field} = shift }
return $self->{$field};
}
Your getset generator may need to be updated. ;-)
##############################################
2) use vars (@ISA);
This is copied from Chapter 31.
31.21. use vars
use vars qw($frobbed @munge %seen);
This pragma, once used to declare a global variable, is now somewhat
deprecated in favor of the our modifier. The previous declaration is
better accomplished using:
our($frobbed, @munge, %seen);
or even:
our $frobbed = "F";
our @munge = "A" .. $frobbed;
our %seen = ();
#########################################
3) auto getset, again
I really cannot stand individual getset any more, after I read Section
12.7. Do yourself a favor, read it, please. One year ago, I suggest to
use AUTOLOAD replace all getset methods. The idea was mercilessly
extinguish. Now I have big boss's support in his book. Anyone wants to
say anything? ;-) ( I do not mean to use AUTOLOAD again, but the rest
ways in that section should be discussed) Just do not stay your Perl
wisdom and braveness at high school, though your bioinformatics
achievement reach above the Ph. D height.
I prefer the idea on Section 12.7.4. Generating Accessors with
Closures. It is listsub'able.
my $0.02
Juguang
More information about the Bioperl-l
mailing list