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

Felipe Cypriano felipe at cypriano.me
Tue Dec 22 17:45:45 CST 2015


I could read the entire conversation because following the web archives is super unintuitive. So feel free to answer me with a bunch of links if you think my question was already answered.

Isn't this proposal solving a problem that in practice doesn't exist or isn't common enough to be worth a language level fix? I'm trying to find an example of a common problem - in any language - that would benefit by having final/sealed by default.

---
Felipe Cypriano

> On Dec 22, 2015, at 3:22 PM, Greg Parker via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Dec 22, 2015, at 11:31 AM, Kevin Ballard via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> UIKit classes aren't subclassable because of a lack of sealed-by-default, they're subclassable because until very recently there was no way to mark classes as not being subclassable.
> 
> There are two historical ways to disallow subclassing of public classes.
> 1. Perform an isa check in your -init method and halt if it's not your class. Attempts to subclass will get runtime errors.
> 2. Mark your class's metaclass symbol as un-exported. Attempts to subclass will get link-time errors.
> 
> Both are used but neither is common.
> 
> 
>> Whether the language has final-by-default/sealed-by-default doesn't really affect this in any way. I guarantee you that once Apple starts putting Swift code in their frameworks, every single framework class Apple releases is going to make an explicit decision about being final/sealed vs inheritable, and the language defaults won't affect that one bit.
> 
> You may be overestimating Apple's engineers. We're just developers too. Whatever the default is, it will be incorrectly left in place more often than you'd like.
> 
> 
> -- 
> Greg Parker     gparker at apple.com     Runtime Wrangler
> 
> 
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151222/e7695348/attachment.html>


More information about the swift-evolution mailing list