<div dir="ltr">Actually, Curt, not that I'm in favor of this proposal, but you inspired an interesting thought--I think that if extensions were more powerful (e.g. stored properties), then having closed classes by default might not be such a big deal. What's the difference between using a `MyViewController` subclass throughout your app to hack around Cocoa's limitations and writing an extension for UIViewController to use app-wide? The only significant difference would probably be a couple fewer hackarounds in the UIViewController case. <div><br></div><div>Of course, it would break a lot of existing code <b>without a way to automatically migrate it</b>. That's a deal breaker for me.</div></div><br><div class="gmail_quote"><div dir="ltr">On Sat, Dec 19, 2015 at 10:09 PM Curt Clifton via swift-evolution <<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="auto"><div>I'm not sure how many minuses I have to give, but I'd give them all to this proposal.</div><div><br></div><div>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><br></div><div>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><br></div><div>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><br>Cheers,<div><br></div><div>Curt</div><div><br></div><div>*-<span style="background-color:rgba(255,255,255,0)"> and am thrilled with the property behaviors proposal for this use case</span></div><div><br></div></div></div><div dir="auto"><div><br>On Dec 17, 2015, at 5:55 PM, Joe Groff via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br><br></div><blockquote type="cite"><div><br><div><blockquote type="cite"><div>On Dec 17, 2015, at 5:41 PM, Rod Brown via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">My opinion is -1 on this proposal. Classes seem by design to intrinsically support subclassing.</div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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><br></div><div>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><br></div><div>-Joe</div><br><blockquote type="cite"><div><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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 style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><blockquote type="cite"><div>On 18 Dec 2015, at 10:46 AM, Javier Soto via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div dir="ltr">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><br></div><div>Thanks!</div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Dec 8, 2015 at 7:40 AM Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br></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><br>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><br>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><br>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><br>1) A class is developed without subclassing in mind by one developer.<br>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>3) After the second developer is gone the bugs are discovered, but by this time there are nontrivial dependencies on the subclasses.<br>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><br>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><br>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><br>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><br>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><br>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><br>Matthew<br><br>Sent from my iPad<br><br>On Dec 7, 2015, at 10:30 PM, John McCall <<a href="mailto:rjmccall@apple.com" target="_blank">rjmccall@apple.com</a>> wrote:<br><br>>>> On Dec 7, 2015, at 7:18 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:<br>>>> 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>>><br>>> 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>>><br>>> 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>>><br>>> 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>>><br>>> 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>><br>> 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>><br>> (1) avoiding artificial bookkeeping obstacles while you’re hacking up the initial implementation of a module, but<br>><br>> (2) not letting that initial implementation make implicit source and binary compatibility promises to code outside of the module and<br>><br>> (3) providing good language tools for incrementally building those initial prototype interfaces into stronger internal abstractions.<br>><br>> 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>><br>> 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>><br>> John.<br>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></blockquote></div><div dir="ltr">--<span> </span><br></div>Javier Soto<span> </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" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span> </span>_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></div></blockquote></div><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing: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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span>_______________________________________________</span><br style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=87iKe3ucuzI0AomIMnNGId9Z44fJ2uc4Nj4u1iL4OH2lHchdyOvVo8coY7LvtttJM0pHXv7qQw0mXblJta7J6NbFwuhQMp79D-2Bvx4wtJDSwbm1r1PNTQ-2FrnoIE8gtWID5eRsybprO9vn7f3SwTD9bC2sdXA7XPoBzzerIFgx6Fr6rItCcdj0V0-2By418yNCt3Wn15oEIptoxj0l3hwqF49jo3eALpnY7fsIDBjE7e52U-3D" alt="" width="1" height="1" border="0" style="min-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">
</div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=8CZIdLciSFC-2BO5jF-2FiP8qN7dBFsgCUZ50wdTsolcRPfps2onpmCTRhcQkmziU3gSMm1phgVFU5TKIR1wL5T2jMoB3lkTpMlAd1JdcqMmqadza5hxYFKGZ1IJPfa7rBHJShJHjMmZHmHE3cUqYZDwA6dire7Qj5YXkK3JYinmTRPYPsak515QPwGRTnm-2BUIhcKSQevhYtMR0NhhA3xozMLPwJzt1XdCgCCCOTNU6Wwwo-3D" alt="" width="1" height="1" border="0" style="min-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">
</div>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>