<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=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jun 29, 2016, at 08:49, Xiaodi Wu &lt;<a href="mailto:xiaodi.wu@gmail.com" class="">xiaodi.wu@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">On Tue, Jun 28, 2016 at 9:06 PM, Jordan Rose via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><div class="gmail_extra"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jun 28, 2016, at 19:03, Matthew Judge &lt;<a href="mailto:matthew.judge@gmail.com" target="_blank" class="">matthew.judge@gmail.com</a>&gt; wrote:</div><br class=""><div class=""><div dir="auto" class=""><div class=""></div><div class="">Comments inline.</div><div class=""><br class="">On Jun 28, 2016, at 04:14, David Hart via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class="">Hello everybody,<div class=""><br class=""></div><div class="">I tried using the access rules defined in SE-0025 in some code of mine to see what effect it would have. I came out of the experiment more disappointed than I thought. Here are several reasons:</div><div class=""><br class=""></div><div class="">1) The new rules make `private` more prominent compared to `fileprivate` (the latter has a somewhat worse name). But at the same time, the Swift community has developed a style of coding where a type is defined through a set of extensions. To hide members from other types, but have access to them inside the type extensions, we have often used `private` and placed the type and its extensions in the same file. Because `private` is scoped, we are forced into using `fileprivate` pervasively (which is uglier), using `internal` instead (which is less safe) or moving the extension code into the type's scope (which is against the way Swift code is being written today). All of these options look worse to be than before SE-0025.</div></div></blockquote><div class=""><br class=""></div>If I understand SE-0025 (even with the amendment) you can still spell the access modifier to types as 'private' and get the same characteristics as the pre-SE-0025 meaning or private, so I'm not sure I understand the concern here. However (continued below)<br class=""><blockquote type="cite" class=""><div class=""><div class=""><br class=""></div><div class="">2) The new amended rules look complicated to me. I think they have the risk of being confusing in practice, but we’ll have to see.</div><div class=""><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">I definitely agree that the amended rules look complicated. It seems to me that the amended set of rules is favoring simplifying the implementation over simplifying the mental model.</div><div class=""><br class=""></div><div class="">My impression of what SE-0025 decided was that 'private' meant private to the enclosing scope. If the access modifying 'private' was applied to a type at the file scope, then it was synonymous with fileprivate and the default access of members of that type should be fileprivate.</div><div class=""><br class=""></div><div class="">If a inner type was declared private, than the default access of members of that inner type should be private to the Outer type, not fileprivate. There is currently no way of expressing this access explicitly, but it does not seem like an especially useful thing to need to spell.</div><div class=""><br class=""></div><div class="">Said in code, my impression of SE-0025 is that&nbsp;</div><div class=""><br class=""></div><div class="">private class Outer { // exactly equivalent to fileprivate</div><div class="">&nbsp; &nbsp; var myVar = 0 // default: fileprivate</div><div class="">&nbsp; &nbsp; private class Inner { // private to Outer</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; var hiddenVar = 0 // default: private to Outer</div><div class="">&nbsp; &nbsp; &nbsp; &nbsp; private var reallyHiddenVar = 0 // default private to Inner</div><div class="">&nbsp; &nbsp; }</div><div class="">}</div></div></div></blockquote><br class=""></div></span><div class="">This is definitely one of the considered alternatives. Both Brent and I didn’t like the idea of an access level that you couldn’t actually spell, and even if we got past that, we’d still need a way to refer to it in documentation and diagnostics. I would count that as a larger change than just allowing ‘fileprivate’ in places that previously would have been called redundant.</div></div></blockquote><div class=""><br class=""></div><div class="">I'm late to the party here, but I share the feeling that perhaps the amendment introduces a complicated mental model. But a lightbulb went off reading the amendment, specifically this parenthetical statement:</div><div class=""><br class=""></div><div class="">"(The members [defaulting to fileprivate inside a private type] still cannot be accessed outside the enclosing lexical scope because the type itself is still private, i.e. outside code will never encounter a value of that type.)"</div><div class=""><br class=""></div><div class="">Given that this is the case, wouldn't the same problem be entirely obviated by the following change to the formal rules:</div><div class="">The default level of access control within any type (public, internal, fileprivate, or private) is `internal`.<br class=""></div><div class=""><br class=""></div><div class="">In the case of fileprivate or private types, the `internal` members still cannot be accessed where the containing type cannot be accessed.</div></div></div></div></div></blockquote><br class=""></div><div>That does seem simpler at first, but it doesn’t remove any of the later, more complicated rules about <i class="">minimum</i>&nbsp;access, and when you can use a less accessible type in a (formally but not in practice) more-accessible declaration. Once those are in place, it seems better to use fileprivate, as the next level up, so that we can still warn about mistaken uses of ‘internal’, and so that we don’t have to special-case code later on in the pipeline that uses visibility to optimize.</div><div><br class=""></div><div>(Alternately, I don’t think that’s the part of the mental model people are having trouble with.)</div><div><br class=""></div><div>Jordan</div><br class=""></body></html>