<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">Yeah, this really is a difficult one.</div><div class=""><br class=""></div><div class="">Adding final seems to be a risky thing at all, from a library or framework standpoint. As you say, there is hubris there in the suggestion “assume we’re right, and you can’t work around us.” I can see developer relations being inundated and unable to provide effective workarounds when the assumption is closed frameworks and finalised subclassing.</div><div class=""><br class=""></div><div class="">If they allow final in public frameworks, the default of “sealed” as mentioned by Jordan Rose makes sense. Closing an API further at a later date creates hell for those who subclass classes “hoping” that classes don’t become “finalised”. How do you handle such cases? It’s better than the alternatives.</div><div class=""><br class=""></div><div class="">But that suggests that indeed there is a greater problem here. Final in end products makes sense. It provides clarity, and allows optimisations. But in frameworks? For those who rely on the frameworks, the ability to subclass to avoid a bug, or to add functionality, while unintended and potentially unsafe, is something we use to develop apps, and how we inspire development of the framework. I think this risks stifling creativity and blocking effective workarounds to bugs.</div><div class=""><br class=""></div><div class="">If we are to add finalisation to API for frameworks, it makes sense to do “Sealed” by default as discussed. But perhaps it needs to be examined if we really want this aggressive optimisation and restriction on frameworks at all.</div><div class=""><br class=""></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 20 Dec 2015, at 2:09 PM, Curt Clifton via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class="">I'm not sure how many minuses I have to give, but I'd give them all to this proposal.</div><div class=""><br class=""></div><div class="">Anyone who tries to ship products on release day of Apple's operating system updates spends most of August and September writing horrible hacks so that their users are insulated from OS bugs as much as possible. All software has bugs, frameworks included. Please don't take away our tools for working around those bugs. Making classes final by default assumes a level of perfection on the part of framework developers that is not achievable.</div><div class=""><br class=""></div><div class="">Yes, subclassing a class that wasn't designed to be subclassed has serious risks. Thoughtful developers sometimes take on those risks in order to serve their customers.</div><div class=""><br class=""></div><div class="">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.</div><div class=""><br class="">Cheers,<div class=""><br class=""></div><div class="">Curt</div><div class=""><br class=""></div><div class="">*-<span style="background-color: rgba(255, 255, 255, 0);" class=""> and am thrilled with the property behaviors proposal for this use case</span></div><div class=""><br class=""></div></div><div class=""><br class="">On Dec 17, 2015, at 5:55 PM, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 17, 2015, at 5:41 PM, Rod Brown via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">My opinion is -1 on this proposal. Classes seem by design to intrinsically support subclassing.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">What if one framework provider thinks “you won’t need to subclass this ever” but didn’t realise your use case for doing so, and didn’t add the keyword? When multiple developers come at things from different angles, the invariable situation ends with use cases each didn’t realise. Allowing subclassing by default seems to mitigate this risk at least for the most part.</div></div></blockquote><div class=""><br class=""></div><div class="">Frameworks change, and if the framework author didn't anticipate your use case for subclassing, they almost certainly aren't going to anticipate it while evolving their implementation and will likely break your code. Robust subclassability requires conscious design just like all other aspects of API design.</div><div class=""><br class=""></div><div class="">-Joe</div><br class=""><blockquote type="cite" class=""><div class=""><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I think this definitely comes under the banner of “this would be nice” without realising the fact you’d be shooting yourself in the foot when someone doesn’t add the keyword in other frameworks and you’re annoyed you can’t add it.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 10:46 AM, Javier Soto via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">Does it seem like there's enough interesest in this proposal? If so, what would be the next steps? Should I go ahead and create a PR on the evolution repo, describing the proposal version that Joe suggested, with classes closed for inheritance by default outside of a module?<div class=""><br class=""></div><div class="">Thanks!</div></div><br class=""><div class="gmail_quote"><div dir="ltr" class="">On Tue, Dec 8, 2015 at 7:40 AM Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;">I understand the rationale, I just disagree with it.<br class=""><br class="">IMO adding a keyword to state your intention for inheritance is not a significant obstacle to prototyping and is not artificial bookkeeping. I really don't understand how this would conflict with "consequence-free" rapid development. It is a good thing to require people to stop and think before using inheritance. Often there is a more appropriate alternative.<br class=""><br class="">The assumption that it is straightforward to fix problems within a module if you later decide you made a mistake is true in some respects but not in others. It is not uncommon for apps to be monolithic rather than being well factored into separate modules, with many developers contributing and the team changing over time. While this is not ideal it is reality.<br class=""><br class="">When you have the full source it is certainly *possible* to solve any problem but it is often not straightforward at all. Here is an example of a real-work scenario app developers might walk into:<br class=""><br class="">1) A class is developed without subclassing in mind by one developer.<br class="">2) After the original developer is gone another developer adds some subclasses without stopping to think about whether the original developer designed for subclassing, thereby introducing subtle bugs into the app.<br class="">3) After the second developer is gone the bugs are discovered, but by this time there are nontrivial dependencies on the subclasses.<br class="">4) A third developer who probably has little or no context for the decisions made by previous developers is tasked with fixing the bugs.<br class=""><br class="">This can be quite a knot to untangle, especially if there are problems modifying the superclass to properly support the subclasses (maybe this breaks the contract the superclass has with its original clients).<br class=""><br class="">It may have been possible to avoid the whole mess if the second developer was required to add 'inheritable' and 'overrideable' keywords or similar. They are already required to revisit the source of it while adding the keywords which may lead to consideration of whether the implementation is sufficient to support inheritance in their currently intended manner.<br class=""><br class="">Implementation inheritance is a blunt tool that often leads to unanticipated problems. IMO a modern language should steer developers away from it and strive to reduce the cases where it is necessary or more convenient. Making final the default would help to do this.<br class=""><br class="">Supporting sealed classes and methods that can only be subclassed or overridden within the same module is not in conflict with final by default. Both are good ideas IMO and I would like to see both in Swift.<br class=""><br class="">I hope the core team is willing to revisit this decision with community input. If not I will let it go, although I doubt I will ever agree with the current decision.<br class=""><br class="">Matthew<br class=""><br class="">Sent from my iPad<br class=""><br class="">On Dec 7, 2015, at 10:30 PM, John McCall <<a href="mailto:rjmccall@apple.com" target="_blank" class="">rjmccall@apple.com</a>> wrote:<br class=""><br class="">>>> On Dec 7, 2015, at 7:18 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:<br class="">>>> Defaults of public sealed/final classes and final methods on a class by default are a tougher call. Either way you may have design issues go unnoticed until someone needs to subclass to get the behavior they want. So when you reach that point, should the system error on the side of rigid safety or dangerous flexibility?<br class="">>><br class="">>> This is a nice summary of the tradeoff. I strongly prefer safety myself and I believe the preference for safety fits well with the overall direction of Swift. If a library author discovers a design oversight and later decides they should have allowed for additional flexibility it is straightforward to allow for this without breaking existing client code.<br class="">>><br class="">>> Many of the examples cited in argument against final by default have to do with working around library or framework bugs. I understand the motivation to preserve this flexibility bur don't believe bug workarounds are a good way to make language design decisions. I also believe use of subclasses and overrides in ways the library author may not have intended to is a fragile technique that is likely to eventually cause as many problems as it solves. I have been programming a long time and have never run into a case where this technique was the only way or even the best way to accomplish the task at hand.<br class="">>><br class="">>> One additional motivation for making final the default that has not been discussed yet is the drive towards making Swift a protocol oriented language. IMO protocols should be the first tool considered when dynamic polymorphism is necessary. Inheritance should be reserved for cases where other approaches won't work (and we should seek to reduce the number of problems where that is the case). Making final the default for classes and methods would provide a subtle (or maybe not so subtle) hint in this direction.<br class="">>><br class="">>> I know the Swift team at Apple put a lot of thought into the defaults in Swift. I agree with most of them. Enabling subclassing and overriding by default is the one case where I think a significant mistake was made.<br class="">><br class="">> Our current intent is that public subclassing and overriding will be locked down by default, but internal subclassing and overriding will not be. I believe that this strikes the right balance, and moreover that it is consistent with the general language approach to code evolution, which is to promote “consequence-free” rapid development by:<br class="">><br class="">> (1) avoiding artificial bookkeeping obstacles while you’re hacking up the initial implementation of a module, but<br class="">><br class="">> (2) not letting that initial implementation make implicit source and binary compatibility promises to code outside of the module and<br class="">><br class="">> (3) providing good language tools for incrementally building those initial prototype interfaces into stronger internal abstractions.<br class="">><br class="">> All the hard limitations in the defaults are tied to the module boundary because we assume that it’s straightforward to fix any problems within the module if/when you decided you made a mistake earlier.<br class="">><br class="">> So, okay, a class is subclassable by default, and it wasn’t really designed for that, and now there are subclasses in the module which are causing problems. As long as nobody's changed the default (which they could have done carelessly in either case, but are much less likely to do if it’s only necessary to make an external subclass), all of those subclasses will still be within the module, and you still have free rein to correct that initial design mistake.<br class="">><br class="">> John.<br class="">_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div><div dir="ltr" class="">--<span class="Apple-converted-space"> </span><br class=""></div>Javier Soto<span class="Apple-converted-space"> </span><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=a745LmqnDfg8U5xkzxO94fzXSZ0ZB2d7MXjmVBHs4IEjC9AdJEh2Zm1Nk-2BN4vporYg4tVaaHg09QtC-2Bc0h5S3HrI3mxzngl1iy2WOhuOLUQvdzzNAhAMMoIEAXqj6VPGJHrDWqEyZLS3a-2BppbOuNPz9a0-2Fa9EPzk3H5gVR66zsPHd35Ur2oQ5j83-2Bu-2Fxm6TGoeeXY7lKJIvFEArWZ5pgkh3hf-2BTjFYN3vBgIjbD39MU-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"><span class="Apple-converted-space"> </span>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn-2FLQLXvGODLStLukegq1PTV0HpT8n4xsDAKCeXG7J4VNn034NO6JQbzvdPM1ad4UNlVcrmhlndCbDAD4lVklFcpx0L7LWCvnALTS2j7laoLIcb5JGbr91ZGHejo0iG0DYfXJk2jreVxk5PNdXsBk8uXi5yt0CTtH3EX2pxid8pK-2FpslmqW9ETQSfd4ZZp8F4k8-3D" alt="" width="1" height="1" border="0" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="mailto:swift-evolution@swift.org" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">swift-evolution@swift.org</a><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class="">
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=87iKe3ucuzI0AomIMnNGId9Z44fJ2uc4Nj4u1iL4OH2lHchdyOvVo8coY7LvtttJM0pHXv7qQw0mXblJta7J6NbFwuhQMp79D-2Bvx4wtJDSwbm1r1PNTQ-2FrnoIE8gtWID5eRsybprO9vn7f3SwTD9bC2sdXA7XPoBzzerIFgx6Fr6rItCcdj0V0-2By418yNCt3Wn15oEIptoxj0l3hwqF49jo3eALpnY7fsIDBjE7e52U-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div></blockquote><blockquote type="cite" class=""><div class=""><span class="">_______________________________________________</span><br class=""><span class="">swift-evolution mailing list</span><br class=""><span class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a></span><br class=""><span class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br class=""></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=a745LmqnDfg8U5xkzxO94fzXSZ0ZB2d7MXjmVBHs4IFOFbuS95GElmZOpdQCxhxWkOu0AQPsgVkkvCoSduvKUf84iAoOL-2FcFfWIZMPct4VliO5YUjozTaYnjGM3SDtq79Ugq9fh4JzVxTuG47gbXeQbR-2B9FuRGt8u8kBGdLkc8Fukj-2FCxjFa5mA4UB0j9Q3cMHcERh2SRbEli34NhtxgzKlY4WD2Elg0DZgiznXOEgs-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>