On Tue, 01 Sep 2009 10:47:36 +0200, Corrado <ct...@york.ac.uk> wrote:

Thanks Duncan, Spencer,

To clarify, the situation is:

1) I have no reasons to choose S3 on S4 or vice versa, or any other coding
convention
2) Our group has not done any OO developing in R and I would be the first, so I
can set up the standards
3) I am starting from scratch with a new package, so I do not have any code I
need to re-use.
4) I am an R OO newbie, so whatever I can learn from the beginning what is
better and good for me.

From my experience I can recommend tree things:

1) If hierarchy of your classes is complicated ( i.e. at least 3 levels of inheritance) and/or you intend to merge functionality of several classes into one (multiple inheritance), it's better to use S4, otherwise use S3. Majority of statistical models in R seem not to require even 2 levels of inheritance and OO is used mainly for method dispatch, so S3 is quite sufficient.

2) If your classes are meant to provide functionality for fundamental objects that you intend to use latter to build more complex structures, then use S4 (example could be super.data.frame or super.matrix, or implementation of sets etc). Usually this "fundamental" objects are derived from basic pseudo-classes in R like "function" and "numeric". You can use S4 object to build your S3 objects latter without any trouble. Though starting R 2.8 one can integrate quite happily S3 objects into S4 and even inherit S4 from S3, that is somewhat artificial and generally not encouraged.


3) If you start with S4 try to avoid writing validity and initialization methods at the beginning. Put everything in the constructors, pretty much as in S3 style.

Vitalie.

So the questions would be two:

1) What coding style guide should we / I follow? Is the google style guide
good, or is there something better / more prescriptive which makes our
research group life easier?
2) What class type should I use? From what you two say, I should use S3
because is easier to use .... what are the disadvantages? Is there an
advantages / disadvantages table for S3 and S4 classes?

Thanks


--

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to