<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 Feb 14, 2017, at 9:31 PM, Chris Lattner via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Feb 14, 2017, at 3:20 AM, David Hart <<a href="mailto:david@hartbit.com" class="">david@hartbit.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div dir="auto" class=""><div class=""><br class=""></div><div class="">On 14 Feb 2017, at 09:25, Goffredo Marocchi <<a href="mailto:panajev@gmail.com" class="">panajev@gmail.com</a>> wrote:<br class=""><br class=""></div><blockquote type="cite" class=""><div class=""><meta http-equiv="content-type" content="text/html; charset=utf-8" class=""><div class="">I disagree with that as well as I still think we are damaging the language each time we take a known concept (like access levels) and give new meanings to the same keywords. I still look baffled at the redefinition of do and the addition of repeat for example...</div><div class=""><br class=""></div><div class="">Private, the way it was before, was an admittedly curious take on how most languages mean by private and we have jumped through a lot of hoops to justify why we did not start with Java/C++/C# like access control and augmented it instead of redefining things, omitting others, and then constantly pulling the language left and right with not a lot of permanent consensus either way as this discussion and others before show.</div></div></blockquote><div class=""><br class=""></div><div class="">It's a curious take, but it is a curious take is perfectly coherent with Swift extensions. How else would you access private implementation details from an extension? But putting it in the same file, instead of having to resort to an internal access level.</div></div></div></blockquote><br class=""></div><div class="">Right. Swift is its own language distinct from Java/C++/etc. While it is intentionally designed to remain familiar (and thus reuses many keywords across the language family), it often does so with slightly different meaning / behavior. Consider ‘throw’ for example.</div><div class=""><br class=""></div><div class="">Keeping with the spirit of Swift and staying consistent with its design, I see two plausible meanings for private:</div><div class=""><br class=""></div><div class="">Private could mean either:</div><div class="">1) private to the file (Swift 2 semantics)</div><div class="">2) accessible only to the current type/scope and to extensions to that type that are in the current file.</div><div class=""><br class=""></div><div class="">I don’t think we’ve ever evaluated and debated approach #2 systematically.</div></div></div></blockquote><div><br class=""></div><div>+1 for #2</div><div><br class=""></div><div>I think #2 strikes a really good balance and addresses all the uses of file-private for me personally. I don’t think the argument of trying to prevent people from accessing private members or methods in an extension stands specially when those extension live in the same file. If I really want something to be private then I can declare that inside an extension in which case other extension could not reach it. </div><div><br class=""></div><div><br class=""></div><div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">// File.swift</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">struct</span><span style="font-variant-ligatures: no-common-ligatures" class=""> MyType {</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> myMethod(){}</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">MyType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">private</span><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> myMethodCantBeSeen(){}</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> myExtenMethod1(){</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> myMethod() </span><span style="font-variant-ligatures: no-common-ligatures; color: #1d9421" class="">// Okay #2, in Swift 3 this method needs to be fileprivate</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class=""> }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; min-height: 21px;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""></span><br class=""></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(195, 34, 117);" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class="">extension</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">MyType</span><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> {</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures" class=""> </span><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">func</span><span style="font-variant-ligatures: no-common-ligatures" class=""> myExtenMethod2(){</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-size: 12px;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #000000" class=""> myMethodCantBeSeen()</span><span style="font-variant-ligatures: no-common-ligatures" class="">// inaccessible due to private protection level</span></span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class=""> }</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">}</span></div><div style="margin: 0px; line-height: normal; font-family: Menlo; color: rgb(29, 148, 33);" class=""><span style="font-variant-ligatures: no-common-ligatures; font-size: 12px;" class="">// end of File.swift</span></div></div><div><br class=""></div><div><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><br class=""></div><div class="">-Chris</div><br class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>