<div dir="ltr">I&#39;m in favor of this as an alternative to the previous evolution. Having worked on Swift projects I find that using `private` ends up being very rare when using an extension based style, good intentions and `private` definitions soon convert to `fileprivate` and never back. I think the goal of progressive discovery and trying make the simplest most obvious case work more often breaks down with respect to access control and an extension based architecture. This was not the case in Swift 2 when `internal` and `private` covered everything well with an extension based style. Having mentored people learning swift this is a very surprising discovery, in a language that tries to not be surprising. Barring the revert which I was in favor of this should go a ways to making `private` more useful more often and making `fileprivate` an advanced form of `private` (as intended)? and more rarely used.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Apr 3, 2017 at 2:34 PM, Douglas Gregor via swift-evolution <span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word">Hello Swift Community,<div><br></div><div>In rejecting <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0159-fix-private-access-levels.md" target="_blank">SE-0159</a>, the core team described a potential direction we would like to investigate for “private” access control that admits a limited form of type-based access control within files. The core team is seeking some discussion here and a motivated volunteer to put together a proposal along these lines for review in the Swift 4 time-frame (i.e., very soon). To be clear, the core team it’s sure this is the right direction to go… but it appears promising and we would *love* to be able to settle the access-control issue.</div><div><br></div><div>The design, specifically, is that a “private” member declared within a type “X” or an extension thereof would be accessible from:</div><div><div><br></div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>* An extension of “X” in the same file</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>* The definition of “X”, if it occurs in the same file</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>* A nested type (or extension thereof) of one of the above that occurs in the same file</div><div><br></div><div>This design has a number of apparent benefits:</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>+ “private” becomes the right default for “less than whole module” visibility, and aligns well with Swift coding style that divides a type’s definition into a number of extensions.</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>+ “fileprivate” remains for existing use cases, but now it’s use it more rare, which has several advantages:</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">                </span>+ It fits well with the &quot;progressive disclosure” philosophy behind Swift: you can use public/internal/private for a while before encountering and having to learn about “fileprivate”   (note: we thought this was going to be true of <a href="https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md" target="_blank">SE-0025</a>, but we were clearly wrong)</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">                </span>+ When “fileprivate” occurs, it means there’s some interesting coupling between different types in the same file. That makes fileprivate a useful alert to the reader rather than, potentially, something that we routinely use and overlook so that we can separate implementations into extensions.</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>+ “private” is more closely aligned with other programming languages that use type-based access control, which can help programmers just coming to Swift. When they reach for “private”, they’re likely to get something similar to what they expect—with a little Swift twist due to Swift’s heavy use of extensions.</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>+ Loosening the access restrictions on “private” is unlikely to break existing code.</div><div><br></div><div>There are likely some drawbacks:</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>- Developers using patterns that depend on the existing lexically-scoped access control of “private” may find this new interpretation of “private” to be insufficiently strict</div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>- Swift’s access control would go from “entirely lexical” to “partly lexical and partly type-based”, which can be viewed as being more complicated</div><div><br></div></div><div>Thoughts? Volunteer?</div><div><br></div><div><span class="m_5248283300787605370Apple-tab-span" style="white-space:pre-wrap">        </span>- Doug</div></div><br>______________________________<wbr>_________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/<wbr>mailman/listinfo/swift-<wbr>evolution</a><br>
<br></blockquote></div><br></div>