<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 <<a href="mailto:cacoyi@gmail.com" class="">cacoyi@gmail.com</a>> 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=""> * `<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=""> * `<font face="monospace, monospace" class="">private</font>` alternatively `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(file)</font>`</div><div class=""> * `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(class)</font>`</div><div class=""> * `<span style="font-family:monospace,monospace" class="">private</span><font face="monospace, monospace" class="">(extension)</font>`</div><div class=""> * `<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? This is more verbose than necessary. 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=""> * `<font face="monospace, monospace" class="">public</font>`</div></div></div></div><div> * `<font face="monospace, monospace" class="">module</font>`, the default (currently `internal`).<br class=""> * `<font face="monospace, monospace" class="">file</font>` (currently `private`)<br class=""> * `<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?" - 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=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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="">
> On Jan 25, 2016, at 5:47 PM, Dave Abrahams via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">
><br class="">
><br class="">
> on Mon Jan 25 2016, Ilya Belenkiy <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:<br class="">
><br class="">
>>> Why should the compiler enforce this? That’s my design decision.<br class="">
>><br class="">
>> It would enforce whatever design decision you make.<br class="">
>><br class="">
>>> For the same reason the compiler does not enforce where I have to<br class="">
>>> put „private“ (it can make suggestions like many IDEs do and offer<br class="">
>>> fix-its, like „this method can be made private as it is not used<br class="">
>>> outside the class“ or „this class can be put into its own file as<br class="">
>>> its private methods are not used by other components in this file“.<br class="">
>><br class="">
>> But once you do put it, it enforces it, and that’s the whole point of having access control.<br class="">
>><br class="">
>>> No, there is a clear difference: making the type name part of the<br class="">
>>> variable name enforces no compiler checks whereas putting something<br class="">
>>> into different files does.<br class="">
>><br class="">
>> Similarly, putting all of the source code in the same file is<br class="">
>> equivalent to no checks.<br class="">
><br class="">
> The place where I'm most concerned about this is in playgrounds. If<br class="">
> we're going to use them to teach programming, it should be possible to<br class="">
> demonstrate encapsulation there.<br class="">
><br class="">
<br class="">
</span>Using playgrounds for teaching is a great example of a use case for this. 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. 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="">
> --<br class="">
> -Dave<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="">
<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>