<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="">These apps you’re referring too would still be possible. Reflection and method swizzling is an alternative to subclassing for working around bugs in authors frameworks without exposing the ability to subclass by default across all class types everywhere. In addition, if there are places where the author is casting to the specific type for some reason, the method swizzled approach will still work where as subclassing will not.<div class=""><div class=""><br class=""></div><div class="">While Swift doesn’t have a full on reflection system yet, it’s on the roadmap. I’d much rather see us getting into safer, and frankly more correct, defaults while still providing mechanisms to do, what essentially boil down to hacks, to get stuff working.</div><div class=""><br class=""></div><div class="">-David</div><div class=""><div class=""><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 20, 2015, at 2:53 PM, Charles Srstka 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 style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class="">I agree with this. -1 to the proposal.</div><div class=""><br class=""></div><div class="">Charles</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 17, 2015, at 8:00 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;">To play devils advocate, take for example UINavigationController in UIKit on iOS.</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;">I’ve seen multiple times in multiple projects legitimate reasons for subclassing it, despite the fact that UIKit documentation says we “should not need to subclass it”. So if we relied on Apple to “declare”, they most probably wouldn’t, and these use cases (and some really impressive apps) would become impossible.</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;">While I agree with all points made about “If it’s not declared subclassable, they didn’t design it that way”, I think that ties everyone’s hands too much. There is a balance between safety and functionality that must be worked out. I think this errs way too far on the side of safety.</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;">Rod</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 12:51 PM, Javier Soto <<a href="mailto:javier.api@gmail.com" class="">javier.api@gmail.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">What if one framework provider thinks “you won’t need to subclass this ever”<br class=""><br class="">If the framework author didn't design and implement that class with subclassing in mind, chances are it's not necessarily safe to do so, or at least not without knowledge of the implementation. That's why I think deciding that a class can be subclassed is a decision that should be made consciously, and not just "I forgot to make it final"<br class=""><div class="gmail_quote"><div dir="ltr" class="">On Thu, Dec 17, 2015 at 5:41 PM Rod Brown <<a href="mailto:rodney.brown6@icloud.com" class="">rodney.brown6@icloud.com</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;"><div class="" style="word-wrap: break-word;"><div class="">My opinion is -1 on this proposal. Classes seem by design to intrinsically support subclassing.</div><div class=""><br class=""></div><div class="">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 class=""><br class=""></div><div class="">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=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""></blockquote></div></div><div class="" style="word-wrap: break-word;"><div 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" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""></blockquote></div></div><div class="" style="word-wrap: break-word;"><div class=""><blockquote type="cite" class=""><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" target="_blank" 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></div></blockquote></div></div><div class="" style="word-wrap: break-word;"><div class=""><blockquote type="cite" class=""><div class="">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="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"><span class="Apple-converted-space"> </span>_______________________________________________</div></blockquote></div></div><div class="" style="word-wrap: break-word;"><div class=""><blockquote type="cite" class=""><div 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" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div></blockquote></div></div></blockquote></div><div dir="ltr" class="">--<span class="Apple-converted-space"> </span><br class=""></div>Javier Soto</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=kND2tqgLiolwf1-2Bhgg7fFiaPS455NT9j3CATwJCX709yiEQ50E-2FgbXay44G0Ga6dCgp-2FolEGrARnyHb3-2F7EEkf3pPXI0XuAMNrJcgNAUCb3JJ2-2BpAqTHiekFOTFk-2BHsiKHzKwOgWY8p-2F-2B-2F3KCcjRnYsSPkrnasp875fTHCLE4gCU3-2FNdqxZiMajMUl-2FtFJ4H-2Fh8k3v4Jem2-2BNY3F-2Bu8s8dbQZ0bAPIbx0GtZxs9Yw7U-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><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><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=nE9rxSXA5G4kxsTVkgv43pXkLx-2B36P-2BPNJufHeY0dgfefCkS0-2F3MG7rNizaSDp7K6f-2Btvn0itVLanFMGep-2Fk64wXlQqzVHLDOXGvhnAgPTFKvNeUPXu3tBjSlBGTVacssJM8w5pCp-2Bw21c-2BkKZlgo1GjpvWgxAlnIc-2FQgOYfERgzW2aR9XBwhTR5mmv8K5J5k3r4774WM-2Bs16ZYAbk4oeg-3D-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=""></div></div></div></div></body></html>