-
Notifications
You must be signed in to change notification settings - Fork 1.5k
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
decide exactly what should be prohibited for final classes #813
Comments
This comment was marked as outdated.
This comment was marked as outdated.
We've been saying one of the important things about final classes is that you can add names to them without evolution concerns. We could accomplish that by saying |
For myself, the two things I want is for the API and the virtual dispatch to be finalized and thus no longer open to extension. I think that means two key restrictions:
At least initially, I'm not seeing reasons to restrict pointer casts or matching. |
Alternatively, we can add names in an extending adapter without evolution concerns if names in the adapter shadow those in the final class. |
Of the possible rights reserved for
I haven't heard an argument for other restrictions that I've found compelling. |
In particular, I'd like to advocate for a practical rather than philosophical principle here. We should reserve rights for |
Thinking about this more, I've come around to a slightly more restrictive stance here. I think the implicit conversion afforded by deriving is in and of itself surprising for a final class. So the Carbon goal I'm anchoring on here is easy to read and understand. The implicit conversion of inheritance is motivated by the general substitutable approach. For example, given a pointer to a final class A different way of thinking about this: I think a final class should now allow anything like inheritance because the very way we will likely want to teach final is precluding further inheritance. However, I think the things we want to work with any type should also apply to final classes, including adapters. So I think what we want to prohibit for final classes are:
I'm not sure it makes sense to try to enumerate the second bullet point here, as we can't really know the full set of this. So is the concrete restriction in the first bullet point and the general direction of the second OK as an answer here? |
We should have a clear idea of exactly what should be allowed or prohibited for final classes -- exactly which rights are we reserving for class authors?
Some relevant considerations:
FinalClass*
actually points to an instance of the class and not some other type. However, if we permit overloading of implicit conversion, then a user of the class may be able to define other types that implicitly convert toFinalClass*
other than via inheritance.adapter X extends FinalClass
has this capability just likeclass X extends FinalClass
and it's important that we can adapt any type.protected
interface of the class, or to change the implementation of thevirtual
interface of the class. However, (a) in general we want an ACL for this (eg: only these five classes can implement myvirtual
interface), and (b) preventing access to theprotected
interface or implementation of thevirtual
interface does not require that we prevent inheritance.FinalClass*
to a pointer to some enclosing (derived) type. However, we will probably want some general form of this facility (not related to inheritance) as an opt-in facility, since being able to navigate from a pointer to a subobject to a pointer to an enclosing object is a valuable operation.We should be clear on which restrictions we want to enforce and should either apply them consistently or have rationale for why different cases are being handled differently.
The text was updated successfully, but these errors were encountered: