Skip to content
Prev 8933 / 63421 Next

Who to decide what a generic function should look like?

I understand this viewpoint too, but I tend to think about it as
follows. Consider a hierarchy of all possible classes. Excluding
multiple heritance, they could I principle be place in a tree structure
with a root class, which all classes directly or indirectly inherits
from (this is the idea in for instance Java). In R, such a root class
could have the methods print(), as.character() and a few other methods
that you expect all R objects to have. From there on you add new
classes. With this class hierarchy I think about generic functions (as
they work today) as methods that are placed in the root object. However,
why can they not be further down the tree where they can be documented
specifically for that subtree and provide polymorphism from there on?
This should still be (be even more) intutive for the end user I think. 

So not thinking about S3 or S4, but in a longer term, is there a reason
for not going the whole way and having a method dispatching mechanism
that is totally general like in other object-oriented languages? When
asking this, I might reveal that I am not fully confortable with the
differences and pros & cons between scientific programming (with
vectors) and standard object-oriented programming.
This is promising and I am really glad to hear that the problem of
conflicts might be solved. The problem remains though if one decides to
have to different types of classes in one package both with a
normalize() method, meaning that you might have to split up your package
into a bundle of packages. However, this is a much smaller problem since
it can be controlled by the developer.
Duncan, thanks a lot for your reply!

Henrik