<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 Jan 25, 2016, at 8:37 PM, Andrew Bennett &lt;<a href="mailto:cacoyi@gmail.com" class="">cacoyi@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class=""><div class="">I like file scoped private, it's way better than C++'s `friend`. I also often feel that it's unsafe when I've mentally scoped implementation details to a class or extension, but the implementations are in the same file.</div><div class=""><br class=""></div><div class="">I would support something like this:<br class=""></div><div class=""><div class="">&nbsp; &nbsp; * `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(module)</font>` alternatively `<font face="monospace, monospace" class="">internal</font>`, the default.<br class=""></div><div class="">&nbsp; &nbsp; * `<font face="monospace, monospace" class="">private</font>`&nbsp;alternatively&nbsp;`<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(file)</font>`</div><div class="">&nbsp; &nbsp; * `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(class)</font>`</div><div class="">&nbsp; &nbsp; * `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(extension)</font>`</div><div class="">&nbsp; &nbsp; * `<font face="monospace, monospace" class="">public</font>`</div></div></div></div></blockquote><div><br class=""></div><div>I like the basic breakdown of functionality here, but why overload private with so many variations? &nbsp;This is more verbose than necessary. &nbsp;I think we can get away with being more clear and concise (access modifiers are decl modifiers, not keywords so they don’t steal identifiers, IIUC).</div><div><br class=""></div><div>Why not this:</div><div><br class=""></div><div><div dir="ltr" class=""><div class=""><div class="">&nbsp; &nbsp; * `<font face="monospace, monospace" class="">public</font>`</div></div></div></div><div>&nbsp; &nbsp; * `<font face="monospace, monospace" class="">module</font>`, the default (currently `internal`).<br class="">&nbsp; &nbsp; * `<font face="monospace, monospace" class="">file</font>` (currently `private`)<br class="">&nbsp; &nbsp; * `<span class="" style="font-family: monospace, monospace;">private</span>` (no current equivalent: containing scope whether class, struct, enum, extension, etc)</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class=""><div class=""><br class=""></div><div class="">Perhaps this could let us deprecate/remove the keyword `<font face="monospace, monospace" class="">internal</font>`, I'm not sure of many circumstances when you'd actually need to write it.</div><div class=""><br class=""></div><div class="">I also think that `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(module)</font>` is also more intuitively understood than `<span style="font-family:monospace,monospace" class="">internal</span>`.</div><div class=""><br class=""></div><div class=""><b class="">My reasoning:</b></div><div class=""><br class=""></div><div class=""><div class="">This seems to come down to:</div><div class=""><ul class=""><li class="">It lowers the cognitive load if you can put related concepts in the same file.<br class=""></li><li class="">It lowers the cognitive load if you can reduce the number of things a class needs to understand.</li><li class="">People like the current system, its simple and it works for them.</li></ul></div></div><div class="">"Everyone knows that debugging is twice as hard as writing a program in the first place. So if you're as clever as you can be when you write it, how will you ever debug it?" -&nbsp;The Elements of Programming Style<div class=""><br class=""></div></div><div class="gmail_extra"><div class="gmail_quote">On Tue, Jan 26, 2016 at 12:46 PM, Matthew Johnson 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=""><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"><span class=""><br class="">
&gt; On Jan 25, 2016, at 5:47 PM, Dave Abrahams via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;<br class="">
&gt; on Mon Jan 25 2016, Ilya Belenkiy &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class="">
&gt;<br class="">
&gt;&gt;&gt; Why should the compiler enforce this? That’s my design decision.<br class="">
&gt;&gt;<br class="">
&gt;&gt; It would enforce whatever design decision you make.<br class="">
&gt;&gt;<br class="">
&gt;&gt;&gt; For the same reason the compiler does not enforce where I have to<br class="">
&gt;&gt;&gt; put „private“ (it can make suggestions like many IDEs do and offer<br class="">
&gt;&gt;&gt; fix-its, like „this method can be made private as it is not used<br class="">
&gt;&gt;&gt; outside the class“ or „this class can be put into its own file as<br class="">
&gt;&gt;&gt; its private methods are not used by other components in this file“.<br class="">
&gt;&gt;<br class="">
&gt;&gt; But once you do put it, it enforces it, and that’s the whole point of having access control.<br class="">
&gt;&gt;<br class="">
&gt;&gt;&gt; No, there is a clear difference: making the type name part of the<br class="">
&gt;&gt;&gt; variable name enforces no compiler checks whereas putting something<br class="">
&gt;&gt;&gt; into different files does.<br class="">
&gt;&gt;<br class="">
&gt;&gt; Similarly, putting all of the source code in the same file is<br class="">
&gt;&gt; equivalent to no checks.<br class="">
&gt;<br class="">
&gt; The place where I'm most concerned about this is in playgrounds.&nbsp; If<br class="">
&gt; we're going to use them to teach programming, it should be possible to<br class="">
&gt; demonstrate encapsulation there.<br class="">
&gt;<br class="">
<br class="">
</span>Using playgrounds for teaching is a great example of a use case for this.&nbsp; Thanks for mentioning it!<br class="">
<br class="">
I also think the fact that “surrounding scope” is actually the most frequent use of `private` members (in code I have surveyed) indicates that it is a very reasonable feature request.&nbsp; Allowing us to declare the actual intent aids readability and clarity.<br class="">
<br class="">
-Matthew<br class="">
<div class=""><div class="h5"><br class="">
&gt; --<br class="">
&gt; -Dave<br class="">
&gt;<br class="">
&gt; _______________________________________________<br class="">
&gt; swift-evolution mailing list<br class="">
&gt; <a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">
&gt; <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="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" 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="">
</div></div></blockquote></div><br class=""></div></div></div>
</div></blockquote></div><br class=""></body></html>