[Bioperl-l] bioperl API conventions

Chris Fields cjfields at uiuc.edu
Fri Mar 3 22:19:00 UTC 2006


> -----Original Message-----
> From: bioperl-l-bounces at lists.open-bio.org [mailto:bioperl-l-
> bounces at lists.open-bio.org] On Behalf Of Rutger Vos
> Sent: Friday, March 03, 2006 3:48 PM
> To: bioperl list
> Subject: [Bioperl-l] bioperl API conventions
> 
> Hi all,
> 
> I've noticed that many bioperl objects don't separate getters from
> setters, e.g.:
> 
> my $branchlength = $node->branchlength; # now it's a getter
> $node->branchlength($branchlength); # now it's a setter
> 
> Is this approach carved in stone? Or could one contribute objects to the
> project that do:
> 
> my $branchlength = $node->get_branchlength;
> $node->set_branchlength($branchlength);
> 
> To me (and, apparently, to Damian Conway, see "perl best practices" :)
> the latter approach is better, as it takes away some ambiguity,
> especially w.r.t setting false-but-defined values (bugs could emerge
> where arguments are erroneously tested for truth rather than
> definedness) and resetting fields to undef.
 
Careful, don't open up that can of worms.  There was talk of this in the
mail list archives.  These threads cover much of the discussion; to get the
gist, trace back to the beginning and read through.  The second thread is
more fun:

http://portal.open-bio.org/pipermail/bioperl-l/2003-January/010863.html

http://portal.open-bio.org/pipermail/bioperl-l/2003-December/014374.html

The last one is from around the time bioperl 1.4 was released.  I believe it
is enforced somewhat but not religiously.  I know AUTOLOAD is not supposed
to be in code but I have seen it in core (Bio::Tools::Run::StandAloneBlast
has it, I believe).  I believe it has more to do with having similar methods
in all the modules, and AUTOLOAD is avoided b/c explicit get/setters make
understanding code a lot easier.  I personally am looking forward to seeing
how everybody here deals with Pugs/Perl6 (yet another can of worms); OOP in
Perl6 looks quite different from Perl5!

> Also, is it okay to have separate getters and setters in your own
> objects, but implement interfaces that do the combined get/setter thing
> using aliasing?
> 
> Thanks,
> 
> Rutger
> 
> --
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> Rutger Vos, PhD. candidate
> Department of Biological Sciences
> Simon Fraser University
> 8888 University Drive
> Burnaby, BC, V5A1S6
> Phone: 604-291-5625
> Fax: 604-291-3496
> Personal site: http://www.sfu.ca/~rvosa
> FAB* lab: http://www.sfu.ca/~fabstar
> Bio::Phylo: http://search.cpan.org/~rvosa/Bio-Phylo/
> ++++++++++++++++++++++++++++++++++++++++++++++++++++
> 
> 
> _______________________________________________
> Bioperl-l mailing list
> Bioperl-l at lists.open-bio.org
> http://lists.open-bio.org/mailman/listinfo/bioperl-l



Christopher Fields
Postdoctoral Researcher - Switzer Lab
Dept. of Biochemistry
University of Illinois Urbana-Champaign





More information about the Bioperl-l mailing list