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

Steven Lembark lembark@wrkhors.com
Sat, 16 Nov 2002 17:36:24 -0600


> Remember that all methods must be pre-declared (using "sub foo;")
> otherwise you can run into method lookup problems - if a super class
> has a method that should be overridden in the subclass but hasn't been
> declared then the AUTOLOAD in the subclass will _not_ be called.
> That's because the method lookup searches for what's been declared
> before falling back to trying AUTOLOADs.

Use of AUTOLOAD would be to instantiate boilerplate
methods -- mainly accessors. If someone wanted to
overload a base class' accessor they'd probably have
defined the thing in their class. At that point the
declaration would be done with the definition (which
amounts to the same thing).

> Another problem is that once the AUTOLOAD for a subclass has been
> called there's no way for it to say "sorry, can't load that one,
> please keep trying elsewhere". But that's generally not an issue
> if all the classes have pre-declared all their methods.

Actually it can using NEXT (originally intended for
daisy-chaining initializers but it works just as well
for AUTOLOAD).

> time fussing about accessor methods. But if you want to know my
> performance perspective it's this: given the slow down demonstrated
> above by just two trivial statements in std() then for maximum
> performance it should be obvious that separate set_* and get_*
> methods are needed so that each can have the smallest amount of
> code, which is probably:
>
> 	sub set_foo { shift->{foo} = shift }
> 	sub get_foo { shift->{foo} }

Which are rather simple autogenerate at runtime...


--
Steven Lembark                               2930 W. Palmer
Workhorse Computing                       Chicago, IL 60647
                                            +1 800 762 1582