[swift-evolution] Final by default for classes and methods

Matthew Johnson matthew at anandabits.com
Wed Dec 23 14:43:27 CST 2015



Sent from my iPhone

On Dec 23, 2015, at 2:35 PM, Brent Royal-Gordon <brent at architechies.com> wrote:

>> If the frameworks are written in Swift, nothing is stopping Apple from slapping 'final' on all the classes they don't want developers to inherit from, even if the proposal is rejected; neither is there anything stopping them from making all their classes inheritable (if that happened to be what they wanted, which it isn't).
> 
> You cannot look at a language simply as a technical artifact. A language creates culture and shapes the systems written in it. It defines not only what is possible and what is not, but also what is preferred and what is discouraged. Defaults matter. If they didn't, people wouldn't be trying to change the default.
> 

Agreed.

> Making `final` the default, or `sealed` the default, encourages the use of closed class hierarchies. It attempts to make inflexibility the preferred form of shared Swift code. I'm not sure that's the right thing to do.
> 

I don't agree with this framing.  IMO it encourages alternative designs emphasizing protocols and composition.  This is a very good thing IMHO.  I like to think of inheritance is a tool is last resort. 

BTW, I am planning a future proposal regarding automatic forwarding which if accepted would make the use of protocols and composition more convenient.

> -- 
> Brent Royal-Gordon
> Architechies
> 


More information about the swift-evolution mailing list