s-news
[Top] [All Lists]

Re: [S] Proposal for S-Plus 5.0 and < 5.0 compatible handling of old cla

To: Frank E Harrell Jr <fharrell@virginia.edu>
Subject: Re: [S] Proposal for S-Plus 5.0 and < 5.0 compatible handling of old classes
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
Date: Thu, 29 Apr 1999 07:22:55 +0100 (BST)
Cc: s-news <s-news@wubios.wustl.edu>
In-reply-to: <004c01be91e0$03c50d20$5ed5bfa8@fharrell.biostat.virginia.edu>
Sender: owner-s-news@wubios.wustl.edu
On Wed, 28 Apr 1999, Frank E Harrell Jr wrote:

> 
> Tim Hesterberg of MathSoft has done a little bit of testing of the following
> on S-Plus 5.x and it seems to work.  That leads to a change to existing
> code so that one version will work both in 5.x and in versions before 5.0:
> 
> Old Coding                New Coding
> k <- class(x)               k <- attr(x, 'class')
> class(x) <- k               attr(x, 'class') <- k
> w <- value; class(w) <- 'myclass' 
>                                    w <- structure(value, class='myclass')
> 
> The last form is particularly handy for returning objects in functions.
> The new approach gets around the non-backward compatibility of
> class() in 5.x without resorting to the somewhat distasteful oldClass().
> Unless someone sees a problem with this, I plan to use the above new
> coding in making changes in my libraries so that they will be compatible with 
> 5.x.
> Please don't blame Tim if there is a problem with this because neither he nor
> MathSoft endorse it - Tim just let me know that it appears to work.

Yes, that works at present (you used to see lots of examples of it in V&R
code). But, I have two objections, enough to take this out of most of our
code.

(1) It uses the representation of class indicators, not the extractor
functions, and that is generally regarded as a bad idea, both from the
point of view of readability and from the point of view of data hiding. In
particular, it relies on the internal representation of oldClass not being
changed in the future.  

In short, it is moving away from object-oriented programming, and in my
view is a lot more `distasteful' than oldClass and oldClass<-.  Those who
have written object$residuals instead of the recommended residuals(object)
will get their comeuppance in a forthcoming version.

(2) Surely the main point of using S-PLUS 5.x (except for Linux users) is
to migrate to the new-style classes. They are not there for fun!  And doing
this proposed conversion just makes that migration harder.  Even if you do
not use proper classes, the new more efficient ways to call compiled code
need extensive code changes.


Our approach is to write master versions of the code and preprocess them
with a Perl script for S-PLUS 3.x/4.x and 5.x.  A lot of the conversions
are automatic.  If you start migrating to genuine S-PLUS 5.x code this
seems the only way to go as the new classes need lots of small differences.
There may also need to be a multiplicity of versions. You have

S-Plus 5.0
     < 5.0

but what about > 5.0 (5.1 is not far off I am told) and I also need
differences for the next member in the 4.x series due to new features. And
this cannot be done cleanly using the S language, as some parts of the
current language (e.g. @) are not syntactically valid in the old. (That
would also introduce a run-time penalty unless done rather obscurely).

Those Perl scripts have slipped out and are used by others: one day soon
I must tidy them up, document them and make them public.

S-PLUS 5.x would be a lot easier to use if MathSoft took migration to the
new language more seriously, but they have gone backwards relative to the
language described in Chambers (1998). Even one reference example of
model-fitting using new-style classes and the appropriate extractor
functions (residuals() and so on) would help.

Brian

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272860 (secr)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu.  To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message:  unsubscribe s-news

<Prev in Thread] Current Thread [Next in Thread>