<div><div class="gmail_quote"><div><br></div><div style="word-wrap:break-word"><div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69)">Hi All,</div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69)">I’ve been following the access control discussion a little and I had an idea that I wanted to throw out here. I know it’s too late and the idea doesn’t provide source compatibility, but it seemed worthwhile to post it anyway. My apologies if something similar has already been proposed.</div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69)">First of all, I propose to use a trailing colon ‘:’ to make it clear that it’s an access control keyword. Secondly, the idea introduces new keywords that clearly describe the scope of access:</div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><br></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><font face="Menlo" style="font-size:11px">scope: (formerly private)</font></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><font face="Menlo" style="font-size:11px">file: (formerly fileprivate)</font></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><font face="Menlo" style="font-size:11px">module: (formerly internal, default)</font></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><font face="Menlo" style="font-size:11px">extern: (formerly public)</font></div><div style="margin:0px;line-height:normal;color:rgb(69,69,69)"><font face="Menlo" style="font-size:11px">extern(open): (formerly open)</font></div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><br></div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69)">Examples:</div></div><div><ol class="m_6409612839568120956code-lines" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;font-family:Helvetica,Arial,sans-serif"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"><span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">extern:</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">class</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">SomePublicClass</span> { <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly public class</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">extern:</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">var</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">somePublicProperty</span> = <span class="m_6409612839568120956m" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207)">0</span> <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly public class member</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">var</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">someInternalProperty</span> = <span class="m_6409612839568120956m" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(28,0,207)">0</span> <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// implicitly internal class member</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">file:</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">func</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">someFilePrivateMethod</span>() {} <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly file-private class member</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">scope:</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">func</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">somePrivateMethod</span>() {} <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly private class member</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px">}</code></li></ol><div><span style="font-size:11px"><br></span></div></div><div><ol class="m_6409612839568120956code-lines" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;font-family:Helvetica,Arial,sans-serif"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"><span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">extern(open):</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">class</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">SomeOpenClass</span> { <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly open class</span></code></li><li></li></ol></div><div><ol class="m_6409612839568120956code-lines" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;line-height:1.6em;list-style:none;font-family:Helvetica,Arial,sans-serif"><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px"> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">extern(open):</span> <span class="m_6409612839568120956kt" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(170,51,145)">func</span> <span class="m_6409612839568120956vc" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(63,110,116)">someOpenMethod</span>() {} <span class="m_6409612839568120956c" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;color:rgb(0,131,18)">// explicitly open class member</span></code></li><li style="border-width:0px 0px 0px 18px;border-left-style:solid;border-left-color:transparent;margin:0px;outline:0px;padding:0px 10px 0px 0px;vertical-align:baseline;white-space:pre-wrap;list-style-type:none"><code class="m_6409612839568120956code-voice" style="border:0px;margin:0px;outline:0px;padding:0px;vertical-align:baseline;font-family:Menlo,monospace;word-wrap:break-word;font-size:11px">}</code></li></ol><div><br></div></div><div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69)">Having the keyword describe the access scope actually fits the access control model of Swift very well. The user doesn’t have to learn what public or private means, but only needs to know the concept. Especially coming from another programming language I think public and private are confusing and breaking with it will signal very clearly that the Swift model is different.</div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><br></div></div><div style="margin:0px;line-height:normal;font-family:'Helvetica Neue';color:rgb(69,69,69);min-height:14px"><div style="margin:0px;line-height:normal">The idea is source breaking, but it’s very easy to deprecate the current syntax with a warning and automatically migrate, because:</div>
<ul>
<li style="margin:0px;line-height:normal">All keywords are redefined, so there can be no confusion with the current syntax.</li>
<li style="margin:0px;line-height:normal">Only redefines the syntax, not the semantics.</li></ul><div><br></div><div>Funny thing, I thought of this last night and when I woke up this morning I read Erica’s proposal that uses many of the same keywords, although in a different way. Telepathy? Or maybe we’re just onto something here?</div><div><br></div><div>I know this will turn everything upside down, but I like the overall consistency, so I just wanted to throw it into the group as the next idea to fix access controls and see if anyone likes it.</div><div><br></div><div>Alternatives considered:</div><ul>
<li style="margin:0px;line-height:normal">‘all’ instead of ‘extern’. This sounds to me as if it can always be accessed from everywhere, which might not be what we want if we introduce submodules.</li></ul><div><br></div><div>Regards,</div><div>Manolo</div><div><br></div><div><br></div></div></div></div></div>