[swift-evolution] [swift-evolution-announce] [Review] SE-0117: Default classes to be non-subclassable publicly

Goffredo Marocchi panajev at gmail.com
Sat Jul 9 03:44:26 CDT 2016

Sent from my iPhone

> On 9 Jul 2016, at 05:39, Jordan Rose via swift-evolution <swift-evolution at swift.org> wrote:
> Of course, Swift doesn’t allow this. If someone outside of the module subclasses ModelBase, there’s no way for them to provide the dynamically-dispatched 'init(context:)’, because they don’t have access to the internal ModelContext.

Shouldn't Swift allow this? Wouldn't it be better if we found a different way to handle this than a brute force "you shall only subclass if I think you should"? Is that really an impossible cause that is worth us going completely the opposite direction of most programming languages?

Can you tell me why the onus should not be on you, on library authors, to use final or an equivalent keyword to indicate no subclassing is allowed and thus make this intentional?

I am really not sold on why classes should not be subclassable by default. Not all classes suffer of the problem you mention and for those cases you should be able to express your intention explicitly. I am quite against this being a compiler default.

I think that security by ignorance, which is what automagically enforced rules tend to produce over time, does have some side effects.

More information about the swift-evolution mailing list