<div style="white-space:pre-wrap">Type based access would be confusing, which is why the proposal was for scoped based access. This means that something is visible only in the scope in which it is defined and is completely sealed from outside of the scope. This way you have to modify the scope to make something more visible, so you can&#39;t just add another extension to make something more visible.<br><br>&gt; Limiting access using scope means another file/module can just add a property/function to make the value public. Confusing type-based and file-based access is a step backwards, and any attempt to add type-based access shouldn&#39;t be a breaking change.</div><br><div class="gmail_quote"><div dir="ltr">On Wed, Mar 16, 2016 at 6:52 AM James Froggatt via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt; wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">I agree with the proposal of ‘inherited’ &amp; ‘declaration’ modifiers.<br>
<br>
Current access modifiers actually guarantee access. Limiting access using scope means another file/module can just add a property/function to make the value public. Confusing type-based and file-based access is a step backwards, and any attempt to add type-based access shouldn&#39;t be a breaking change.<br>
<br>
Replacing internal with private(module) also seems like a step backwards, to me, and in my opinion changes to the ‘internal’ keyword should be part of a separate proposal.<br>
<br>
Inherited &amp; declaration modifiers compose well with existing access-modifiers, are clear in their purpose, can be applied to all access levels, and don&#39;t break existing code.<br>
<br>
------------ Begin Message ------------<br>
Group: gmane.comp.lang.swift.evolution<br>
MsgID: &lt;<a href="mailto:CAPUwzK7YHzwDMTMuH1Qvbojz3%2B9%2BikgJvna3xDhscESVO8YSNQ@mail.gmail.com" target="_blank">CAPUwzK7YHzwDMTMuH1Qvbojz3+9+ikgJvna3xDhscESVO8YSNQ@mail.gmail.com</a>&gt;<br>
<br>
It&#39;s occurring to me, reading these recent posts, that we have two<br>
orthogonal systems of access levels.<br>
<br>
Swift&#39;s current access system is file based; a project file decides which<br>
files comprise a module, and the terms &#39;public&#39;, &#39;internal&#39; and &#39;private&#39;<br>
determine whether a property is accessible to all, accessible only within<br>
files of the module, or accessible only within a file. (This takes on an<br>
extra dimension as files may belong to several modules).<br>
<br>
The concept which began this discussion, and several of the proposed<br>
concepts in this discussion, ask instead for a type-based access system<br>
similar to those in other languages including Objective-C, where &#39;public&#39;,<br>
&#39;protected&#39; and &#39;private&#39; are the terms of choice and they restrict access<br>
to a type or subtypes.<br>
<br>
I think it would be confusing if Swift applied &#39;public&#39; to a concept in the<br>
file-based access system and &#39;private&#39; to a concept in the type-based<br>
access system.<br>
<br>
I would prefer clearer terms which actually mention the restrictions of the<br>
level. For example, &#39;inherited&#39;, not &#39;protected&#39;, in the case of properties<br>
accessible by a class and its subclasses; &#39;declaration&#39;, rather than<br>
&#39;private&#39; or &#39;scoped&#39;, to refer to properties only accessible within a<br>
given type or extension declaration.<br>
<br>
Since, at the moment, a declaration can only occur within one file, I think<br>
this most-restricted level has managed to pass as a level of the file-based<br>
access system. However, if the system is ever extended, we&#39;re going to run<br>
into new syntax decisions where we have &#39;private module&#39; functions<br>
(accessible only within the given type in the same module) trying to<br>
communicate with &#39;protected file&#39; properties (accessible only with the type<br>
and its subtypes in the same file), and that might lead to conflicts, so<br>
perhaps we should decide how those might be declared now.<br>
<br>
On Tue, Mar 15, 2016 at 11:51 PM, Jonathan Hull via swift-evolution &lt;<br>
<a href="mailto:swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org" target="_blank">swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org</a>&gt; wrote:<br>
<br>
&gt;On Tue, Mar 15, 2016 at 2:33 PM Erica Sadun &lt;erica at <a href="http://ericasadun.com" rel="noreferrer" target="_blank">ericasadun.com</a> &lt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>&gt;&gt; wrote:<br>
&gt;<br>
&gt;And again, moving the access control modification to the end just doesn&#39;t look<br>
&gt;right to me or seem to enhance readability. :(<br>
&gt;<br>
&gt;I like Shawn’s proposal better for cases where there are custom<br>
&gt;getter/setter implementations.  We should definitely be able to do:<br>
&gt;<br>
&gt;var foo:Int {<br>
&gt;public get {…}<br>
&gt;private(file) set {…}<br>
&gt;}<br>
&gt;<br>
&gt;In fact, that is what I first tried to do before learning about<br>
&gt;private(set).  But without the implementations, it just seems strange to<br>
&gt;put the scoping after the rest of the declaration (they work above because<br>
&gt;they are *before* the custom getter/setter).<br>
&gt;<br>
&gt;I still like the idea of having the option to use parameter-like syntax<br>
&gt;for cases where you don’t have custom getters/setters:<br>
&gt;<br>
&gt;private var foo:Int<br>
&gt;private(file) var foo:Int<br>
&gt;private(set: file) var foo:Int<br>
&gt;private(get: global, set: file) var foo:Int<br>
&gt;<br>
&gt;<br>
&gt;I guess, if we had some way to represent the standard getter/setter, that<br>
&gt;might work too.  I don’t love it, but maybe with better wording?<br>
&gt;<br>
&gt;var foo:Int{<br>
&gt;public get useDefault<br>
&gt;private(file) set {…}<br>
&gt;}<br>
&gt;<br>
&gt;Thanks,<br>
&gt;Jon<br>
&gt;<br>
&gt;<br>
&gt;On Mar 14, 2016, at 10:22 PM, Patrick Pijnappel &lt;<br>
&gt;<a href="mailto:patrickpijnappel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" target="_blank">patrickpijnappel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>&gt; wrote:<br>
&gt;<br>
&gt;I like Shawn&#39;s proposal:<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt;var foo: Int { private(file) set }<br>
&gt;<br>
&gt;<br>
&gt;&gt;In fact it&#39;s probably more sensible than the current private(set) IMO.<br>
&gt;<br>
&gt;<br>
&gt;For example, we already use<br>
&gt;<br>
&gt;var foo: Int { mutating get { ... } }<br>
&gt;<br>
&gt;and not<br>
&gt;<br>
&gt;mutating(get) var foo: Int { get { ... } }<br>
&gt;<br>
&gt;On Tue, Mar 15, 2016 at 4:13 PM, Patrick Pijnappel &lt;<br>
&gt;<a href="mailto:patrickpijnappel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org" target="_blank">patrickpijnappel-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org</a>&gt; wrote:<br>
&gt;<br>
&gt;&gt;I like Shawn&#39;s proposal:<br>
&gt;&gt;<br>
&gt;&gt;var foo: Int { private(file) set }<br>
&gt;&gt;<br>
&gt;&gt;In fact it&#39;s probably more sensible than the current private(set) IMO.<br>
&gt;&gt;<br>
&gt;&gt;<br>
&gt;&gt;While I like private(get: file, set: module) idea, I think it just gets<br>
&gt;&gt;too inconsistent with private(set: public) and private(set: private) (?!)<br>
&gt;&gt;<br>
&gt;&gt;On Tue, Mar 15, 2016 at 3:39 PM, Jonathan Hull via swift-evolution &lt;<br>
&gt;&gt;<a href="mailto:swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org" target="_blank">swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org</a>&gt; wrote:<br>
&gt;&gt;<br>
&gt;&gt;&gt;*On Mar 14, 2016, at 8:36 PM, Patrick Pijnappel via swift-evolution &lt;swift-evolution at <a href="http://swift.org" rel="noreferrer" target="_blank">swift.org</a> &lt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a>&gt;&gt; wrote:*<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;The only question is (as Sean mentioned) how this combines with the syntax<br>
&gt;&gt;&gt;for setter access level, e.g. the current private(set). Options:<br>
&gt;&gt;&gt;- Unnamed 2nd argument, giving private(file), private(file, set),<br>
&gt;&gt;&gt;private(set).<br>
&gt;&gt;&gt;- Named 2nd argument, giving e.g. private(file), private(file, accessor:<br>
&gt;&gt;&gt;set), private(accessor: set). Less ambiguity but longer.<br>
&gt;&gt;&gt;- Not using multiple arguments, but that&#39;d probably break consistency with<br>
&gt;&gt;&gt;the other unification efforts going on to make everything look like<br>
&gt;&gt;&gt;function calls.<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;What about the following 3 forms?<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;private(file) //both setter and getter have file scope<br>
&gt;&gt;&gt;private(set: file) //setter has file scope.  Equivalent to current<br>
&gt;&gt;&gt;“private(set)&quot;<br>
&gt;&gt;&gt;private(get: module, set: file) //getter has module scope &amp; setter has<br>
&gt;&gt;&gt;file scope<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;It is a bit weird, but we should probably also allow “public&quot; in that<br>
&gt;&gt;&gt;last form: private(get: public, set: module)<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;Thanks,<br>
&gt;&gt;&gt;Jon<br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;_______________________________________________<br>
&gt;&gt;&gt;swift-evolution mailing list<br>
&gt;&gt;&gt;<a href="mailto:swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org" target="_blank">swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org</a><br>
&gt;&gt;&gt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;&gt;&gt;<br>
&gt;&gt;&gt;<br>
&gt;&gt;<br>
&gt;<br>
&gt;<br>
&gt;_______________________________________________<br>
&gt;swift-evolution mailing list<br>
&gt;<a href="mailto:swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org" target="_blank">swift-evolution-m3FHrko0VLzYtjvyW6yDsg@public.gmane.org</a><br>
&gt;<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
&gt;<br>
&gt;<br>
<br>
<br>
<br>
------------- End Message -------------<br>
<br>
<br>
<br>
>From James F<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote></div>