Skip to content
Prev 3552 / 21312 Next

[Bioc-devel] S4 initialize methods (was Re: "patches" for Gviz: utr plotting support and direct BamFile plotting)

Uh, uh,
Seems like I am the bad guy still using the dreaded initialize methods
around here :-(
I do agree with most of what you guys say, but still want to put my two
cents here. My lawyers are preparing a more complete statement at this
point :-)

Having a constructor function to me somewhat implies that you want objects
from that class to be created by the user in a manual process. In more
complex class hierarchies you don't really want that, but rather you want
to pass through all the parent class' instantiations to fill the relevant
slots appropriately. Whenever you need something more complicated than
foo at a=b in these cases I do not see a way around the initializer. For
instance, in Gviz I have a whole bunch of classes that inherit from each
other, each of them grabbing the arguments to fill their slots while
objects are instantiated. The bottom-most of these classes will gobble up
all the arguments that are left over and stick them into a plotting
parameters object. I guess I could have explicit constructors for all of
those classes, and in those explicitly call the parent constructor, thus
walking through the hierarchy, doing whatever magic I need to do to make
things work. Now that doesn't strike me as particularly elegant either,
and I can't see how that would help with the code copying issue.

Another remark regarding validation. For classes with a large memory
footprint I am very much worried about unnecessary copies of the data. For
objects with very light content that are created very often however I care
much more about fast object instantiation. Running through a validation
method each time you create an object adds quite some overhead to this
(and we all know that building S4 methods even without validators is not
cheap at all). I remember there were times when the use of validation
methods for classes was not recommended. And personally I am no big fan of
them for the reasons pointed out by Kasper and Martin before.

That being said, I will take a closer look at my package to figure out a
way to code everything without the initialize methods and report back to
you guys about my success. I do not generally advertise the use use of
initializers (as a matter of fact I am far far away from that), I just
want to stand up here for these cuddly little creatures, threatened by
extinction and make the point that they still do have their rightful place
in our Bioconductor eco system?
Cheers,
Florian