<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="">+1<div class=""><br class=""></div><div class="">[ Long, sorry… ]<br class=""><br class="">This version is a big step forward! Thanks for the continued work and comments...</div><div class=""><br class=""></div><div class="">I want to propose a small <b class="">reframing</b> that I think would help to clarify some of the remaining issues. It’s not really a “counterproposal” because I don’t think it&nbsp;actually changes all that much about the proposal. It’s more a question of how one conceptualizes the changes and fits them into the existing framework.<br class=""><br class=""><b class="">The gist is:</b><font color="#e32400" class=""> </font><font color="#0056d6" class="">let’s let the second shoe drop and admit that in the current proposal, “open” is now an access level modifier, pure and simple.<br class=""></font><br class="">In the original proposal (and the ensuing discussion), there was tacit agreement that subclassability/overridability and access levels should be orthogonal.&nbsp;However, given the direction that the design has taken since then, I think we should revisit that decision.<br class=""><br class="">open <b class="">IS</b> in fact an access level. I can’t say it any better than the proposal itself: <i class="">“Since the first release of Swift, marking a class public has provided two&nbsp;capabilities: it allows other modules to instantiate and use the class, and it also allows other modules to define subclasses of it. Similarly, marking a class&nbsp;member (a method, property, or subscript) public has provided two capabilities: it allows other modules to use the member, and it also allows those modules to&nbsp;override it…This proposal suggests distinguishing these concepts. A public member will only be usable by other modules, but not overridable. An open member&nbsp;will be both usable and overridable. Similarly, a public class will only be usable by other modules, but not subclassable. An open class will be both usable and&nbsp;subclassable.”</i><br class=""><br class="">In other words, subclassability/overridability <i class="">always was </i>an access level issue. <i class="">All we are doing now</i> is subdividing public into two separate sublevels, public and&nbsp;open. Just as public subsumes all the privileges of internal, open subsumes public.<br class=""><br class=""><b class="">Arguments:<br class=""></b><br class=""><b class="">First</b>, the vast majority of resistance to this proposal (including my own, originally) has centered on the sense that coding options are being removed for&nbsp;potentially or partially ideological reasons (see&nbsp;<a href="http://martinfowler.com/bliki/SoftwareDevelopmentAttitude.html" class="">SoftwareDevelopmentAttitude</a>), without clear value being offered in return. Reframing open as an access level&nbsp;<b class="">completely&nbsp;nullifies </b>this objection. “internal” is already the default access level, and the community seems very comfortable with this. For public APIs, developers are now simply&nbsp;required to make a neutral choice between public and open. There’s no strong-arming and no surprising imposition of new restrictions. Developers just have to&nbsp;make exactly the same, explicit access level decisions they did before. (For public API, the default is already so restrictive as to be moot. No accusations of “you picked the wrong default”!)<br class=""><br class=""><b class="">Second</b>,&nbsp;framing open as an access level automatically resolves the ambiguity between proposal options #1 and #2, in favor of #1 (classes can&nbsp;be marked open).&nbsp;The reason there’s ambiguity about this choice is that there’s ambiguity about what open "really is.” Pin down exactly how open fits into the larger language, and the resolution is obvious. We already know what it means for&nbsp;a class and its members to have different access levels: the members are clamped to the access level of&nbsp;the container. All of the arguments that led to this convention — chiefly, that one may want to keep eventual publication in mind while developing and then be able&nbsp;to “flip the switch” in one place —&nbsp;&nbsp;apply equally to the additional privileges of open. &nbsp;</div><div class=""><br class=""><b class="">Third</b>, developers already understand&nbsp;access levels and how they interact.&nbsp;If open is just an access level, all of this proposal’s changes can be fully and&nbsp;naturally described in one line: “public no longer includes the right to subclass or override. To get the behavior formerly known as public, use open instead.” Clear, concise, and not very controversial.</div><div class=""><br class=""><b class="">Fourth</b>, bending over backwards to insist that open is not an access level leads to a variety of weird effects and special cases. For example, the fact that open&nbsp;implies public unless otherwise stated, which is mighty strange for modifiers that are supposedly orthogonal. Not to mention all the potential headbutts mentioned&nbsp;earlier by Xiaodi Wu; I agree that open in combination with internal seems oxymoronic. All of these nits would just go away if open were an access level. Again, all of this is the case because open <b class="">really does</b>&nbsp;quack like an access level and walk like an access level.<br class=""><br class=""><b class="">Points:<br class=""></b><br class=""><font color="#4f7a28" class=""><b class="">Q:</b> “But what about access-leveled entities for which ‘open’ doesn’t make sense? What does ‘open struct’ mean?”<br class=""></font><b class="">A:</b> It doesn’t mean anything and should be an error. Simple. It’s not as if there weren’t all kinds of above-grammar-level restrictions in the current design…<br class=""><br class=""><font color="#4f7a28" class=""><b class="">Q:</b> “What about conflicts with other modifiers, e.g. ‘open is not permitted on declarations that are explicitly final or dynamic’? Isn’t it weird that a simple access level&nbsp;could cause this kind of conflict?”<br class=""></font><b class="">A:</b> Au contraire, it’s final and dynamic that impose special requirements. You can just as easily flip this around: “final may not be applied to objects at the open access level”. Doesn’t that make more sense anyway?<br class=""><br class=""><font color="#4f7a28" class=""><b class="">Q:</b> “You yourself (Garth) have argued that there’s no value to being able to forbid subclassing at the class level, and others have taken this position as well. So why are&nbsp;you now so eager to add&nbsp;‘open’ to class definitions?”<br class=""></font><b class="">A:</b> Because it leads to a simple, consistent, and uncontroversial design. I do think there is value in being able to “flip the switch” at the class level as well. From the technical/compiler&nbsp;perspective, it seems like most benefits derive from method-level restrictions (as the current proposal seems to suggest). However, from the perspective of API&nbsp;clients, the top-level question is always going to be “should I be subclassing this or not?” I wouldn’t argue in favor of a class-level keyword just for the purpose of documenting intention,&nbsp;but since we get it for free with these other benefits, I’m all for it.<br class=""><br class="">Garth</div><div class=""><br class=""><br class=""></div></body></html>