-
Notifications
You must be signed in to change notification settings - Fork 181
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
Class Declaration: final
keyword
#3852
Comments
What if we make classes final-by-default? Kotlin, another popular object-oriented language derived from Java, takes this choice to encourage explicitly documenting support for inheritance as an "opt-in" choice by library authors instead of opt-out: class Foo {} // I can't inherit it
open class Bar {} // I can inherit it See this stackoverflow post for more details. I think it might align with our language's philosophy of good cognitive friction. For interoperability with JSII, we'd have to assume any existing JSII classes from TypeScript are still open since TypeScript/JSII doesn't have a convention for specifying final classes AFAIK. |
I'm into that, considering wing also generally favors immutable-by-default behaviors. I assume the same would apply to interfaces and structs? |
The down side (but this might also be an up side) is when you want to inherit something from some library and there's no real bad reason not to allow this except that the lib's author didn't put the |
@yoav-steinberg Right. I think it's a similar kind of tradeoff as wanting to use a class's private field as if it were public. @MarkMcCulloh Good question. For structs I could see a line of reasoning that when a struct extends another struct, it more closely resembles composition, since you're just adding one bag of fields to another. No code or "behavior" is getting layered through |
My opinion here is not only to be open by default, but also not to bother adding a |
I prefer closed by default and then |
I'm with @yoav-steinberg in this, especially because of the need to extend external libs
|
Hi, This issue hasn't seen activity in 60 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
Hi, This issue hasn't seen activity in 90 days. Therefore, we are marking this issue as stale for now. It will be closed after 7 days. |
The
final
keyword on a class indicates that this class cannot be extended.The text was updated successfully, but these errors were encountered: