[R] Need Advice: Considering Converting a Package from S3 to S4
Terry Therneau
therneau at mayo.edu
Tue Aug 11 18:54:47 CEST 2009
For 90 percent of what I do I strongly prefer the loose (S3) rather than the
rigid (S4) classes. So I'm closer to Rolf. My summary of S4 vs S3
A large increment in
1. nuisance to write
2. difficulty to debug
3. ability to write very obscure code
4. design
Gain
5. ability to direct automatic conversions
6. validate the contents of a class object
For simple objects 5 and 6 can be critical. Consider a date for instance,
which will often be turned into a character, added or subtracted as a numeric,
plotted, etc. Conversely, aspects of 1-4 are less worrisome for a simple
object, particularly #4: I have a reasonable chance of "getting it right" the
first time.
For a complex object such as the result of a coxph fit
fit <- coxph(Surv(time, status) ~ age + sex + treatment)
#5 makes no sense at all: as.numeric(fit)??? Number 4 and 6 are really hard;
after 15+ years of tuning I am still modifying the list of components in a coxph
object. I know more about the computational aspects of Cox models than almost
anyone and still it's not enough. Changes are harder with rigid classes.
With reference to #3 above, for your amusement, look at
www.netfunny.com/rhf/jokes/98/May/straustrup.html
the key line (to me) being "..every C++ programmer feels bound by some mystic
promise to use every damm element of the languange on every project..."
Terry T.
More information about the R-help
mailing list