-
Notifications
You must be signed in to change notification settings - Fork 33
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Persistence of class membership #2
Comments
Yes, I think we should have formal construction and coercion, and direct class assignment should be discouraged if not disallowed. Would you be willing to make a PR adding this as a requirement? |
I do think we need to be a little cautious here — while @wlandau I think you need to be more specific about "attributes being dropped at surprising times". I think most problems are caused by the specific design of the generic/method, but it's hard to know without knowing exactly what you consider to be surprising. |
However, there is a general principle to consider: what should methods do with attributes that they don't know about? These attributes could come from a subclass (and has not defined a more specific method), or could be set by the analyst to store some additional metadata. I think there are only two main choices:
Based on our experiences with the tidyverse, dropping unknown attributes appears to cause quite a lot of pain in the user community, and in practice it appears that relatively few attributes are vectorised so object corruption is relatively rare (and can be fixed by the class maintainer defining a new method). Closely related is the problem of handling subclasses in methods, as discussed in https://adv-r.hadley.nz/s3.html#s3-subclassing — in essence, if you want your class to subclassable, then you have to ensure every method you write uses a generic object constructor. Otherwise the implementor of the subclass has to provide methods for every method that the class provides, meaning that inheritance doesn't save you any work. |
It's not clear where With respect to attribute dropping, in a formal class-based framework, the question does boil down to subclass preservation. In Bioconductor, we've long promoted calling This is a problem for every system that allows for inheritance. Inheritance is a strong form of coupling; in general the subclass must be aware of every super class operation and whether it would violate the contract of the subclass. Perhaps the requirement here is that we should provide tools like |
Sure, thanks @lawremi. I will try to get to it soon. Last week was super busy.
@hadley, I was originally thinking of the behavior of |
I wonder, could the new system allow the class author to decide on a case by case basis? I agree, sometimes corrupt objects result from keeping unknown attributes. At other times, all the user wants to do with the subclass is to add new |
While I mostly agree that extending S3 is reasonable, I am a bit concerned about the fluidity of the
class
attribute for our purposes. Specifically,class<-()
etc.Do we want safeguards and formalization around class membership? Maybe formal construction/casting/coercion in addition to the already proposed validation?
The text was updated successfully, but these errors were encountered: