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

Matthew Johnson matthew at anandabits.com
Mon Dec 21 13:32:16 CST 2015


> On Dec 21, 2015, at 1:26 PM, Jordan Rose via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On Dec 20, 2015, at 3:40 , Tino Heth via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> Frankly, I think having `final` in the language at all is a mistake. While I agree that we should prefer composition to inheritance*, declaring things final is hubris. The only reasonable use case I've seen is for optimization, but that smacks of developers serving the compiler rather than the converse. Bringing an analog of NS_REQUIRES_SUPER to Swift would be most welcome; that's as far as I'd go down the path of dictating framework usage.
>> I really like the direction this discussion has taken ;-):
>> Is there any counter argument beside performance (which imho should always be seen under the aspect of premature optimization) that speaks against making NS_REQUIRES_SUPER the default behavior?
> 
> I personally don't like this but I can't put my finger on why. Obviously there are some things where you really don't need to call super (mostly abstract methods), but you just said "default", which implies that we could have an opt-out attribute.
> 
> I will say, however, that making NS_REQUIRES_SUPER the default for overridable methods is separable from deciding which methods are overridable by default. Making sure the base method is called isn't really the same as knowing the base method is all that's called.

Agree.  There are at least four possibilities from most to least restrictive:

* not overridable
* overridable but requires a call to super in a specific location in the overriding method (i.e. the first or last line)
* overridable but requires a call to super somewhere in the overriding method
* overridable with no restrictions


> 
> Jordan
> 
> 
> _______________________________________________
> 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/20151221/830cd95b/attachment.html>


More information about the swift-evolution mailing list