Re: [Rd] LazyLoad changes the class of objects

From: Gabor Grothendieck <ggrothendieck_at_gmail.com>
Date: Wed, 17 Oct 2007 11:07:14 -0400

On 10/17/07, Henrik Bengtsson <hb_at_stat.berkeley.edu> wrote:
> Yes (on the yes), to second Luke. Here is John Chambers' comment when
> I was bitten by the same "bug" a while ago:
>
> http://tolstoy.newcastle.edu.au/R/devel/02b/0524.html
>
> See also Peter Dalgaard's follow up suggesting to wrap up the
> environment in a list, which will typically be enough. I've been
> using this "trick" successfully in the Object class (R.oo package) for
> several years, where I'm putting the environment in the attributes
> list of an object, i.e. obj <- NA; attr(NA, "..env") <- new.env();
> It turned out at the time that this was slightly faster to access than
> using a list element.

This has all been discussed before but this "trick" is not sufficient for defining an environment subclass because it does not respect inheritance. The subclass writer must replicate all methods that act on environments in a subclass for an environment subclass to have them. Inheritance is completely broken.

If there were N environment methods the writer of an environment subclass would have to write N methods to support them all. On the other hand, if it worked in a true OO way the subclass writer would not have to write anything.

Also suppose a new environment method comes along. In true OO the subclass automatically inherits it but with the "trick" the subclass writer needs to write a new method always mimicing the parent.

This is not how OO is supposed to work.



R-devel_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel Received on Wed 17 Oct 2007 - 15:11:17 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Thu 25 Oct 2007 - 11:37:11 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-devel. Please read the posting guide before posting to the list.