[Bioperl-l] Re: Automatic generation of set and get methods

Hilmar Lapp hlapp@gnf.org
Fri, 15 Nov 2002 10:52:03 -0800


> -----Original Message-----
> From: Steve Chervitz [mailto:stevechervitz@yahoo.com]
> Sent: Thursday, November 14, 2002 11:53 PM
> To: Hilmar Lapp; Lincoln Stein; natg@shore.net
> Cc: bioperl-l@bioperl.org; lstein@lsjs.org; jgrg@sanger.ac.uk
> Subject: RE: [Bioperl-l] Re: Automatic generation of set and 
> get methods
> 
> 
> 
> --- Hilmar Lapp <hlapp@gnf.org> wrote:
> > 
<snip/>
> 
> I agree with Hilmar that in Bioperl as it currently stands, 
> you shouldn't rely
> on the return value from a setter (unless you know what 
> you're doing). If,
> however, all modules used autogenerated accessors, you could 
> then rely on the
> set return value, whatever it is. This would make Bioperl modules more
> predictable, which would be a good thing.
> 

In my opinion the return value of a getter is something where I prefer Bioperl to be not predictable. The host of contributors and consequently coding flavors is diverse, and I'd like to keep it that way without extensive code review and rewrite.

This may just be one of the differences between multi-cultural bioperl and a fully commercial product.

(BTW in this spirit, we do discourage AUTOLOAD and auto-generated methods -- but some contributors do like and have used that. No-one would go and change that code to get rid of auto-generation. Yes, this is not uniform coding style -- bioperl has its Chinatown, Germantown, New London, Little Italy, Disneyland, and so on [no offense if I forgot anyone :) ]. To me this is OK -- in fact somehow I like it in the sense of a utopy.)

<snip/>
> 
> I also like the explicitness of having all methods including accessors
> available in the source. But I've also felt at times burdened 
> by cutting and
> pasting nearly identical code for every field. Here's my 
> accounting of the
> pluses and minuses to help decide the best way to go. Feel 
> free to add &
> comment:
> 
> Advantages of accessor autogeneration:
> 
>    * Frees developer from drudgery of writing routine accessor code

For me this is a click on the bioperl-menu and then menu item 'bioperl field method.' Boom - the method fully implemented with documentation template generated is right there in my code with two mouse clicks (there's a keystroke combination too which I keep forgetting).

If you're not using emacs (bioperl.lisp comes with the dist.), this may be less easy - but people are more than welcome to submit macros that accomplish the same thing in their favourite editor. If you're using an editor lacking macros, chances are you're using a poor editor and should look at emacs anyway :)

What is more drudgery to me is _filling in_ the documentation template. To an API user, this is what's most important though. How would you simplify that?

>    * Reduces chance of bugs within accessor code (e.g., from 
> cut-n-paste)
>    * Guarantees predictability of accessors across all modules

Both solved by the macro.

>    * Simple tests could be autogenerated

That'd be cool. But this doesn't need an auto-generation of methods, right?

>    * Documentation template could be autogenerated

Macro does this.

>    * Reduces amount of routine code within a module so you 
> can focus on the 
>      business logic.

Macro does this. If it's not boilerplate someone's got to code it anyway.

> 
> Disadvantages of autogeneration of accessors:
> 
>    * Code is less explicit; can't see all methods when 
> reading module source
>    * Can't validate data when setting (but see below)
>    * Runtime bugs within autogenerated code harder to track down
>    * Performace hit (maybe, not sure about this)

Allegedly method calls are a performance hit in perl. That's what we've been trying to reduce to make the parsers faster. Every method call is a performance hit because there is apparently no efficient virtual method lookup table.

<snip/>


	-hilmar
-- 
-------------------------------------------------------------
Hilmar Lapp                            email: lapp at gnf.org
GNF, San Diego, Ca. 92121              phone: +1-858-812-1757
-------------------------------------------------------------