[swift-evolution] classprivate protection level?

Adam Kemp adam_kemp at apple.com
Mon Oct 30 14:49:05 CDT 2017


> On Oct 30, 2017, at 11:19 AM, Mike Kluev <mike.kluev at gmail.com> wrote:
> 
> 
> On 30 October 2017 at 18:07, Adam Kemp <adam_kemp at apple.com <mailto:adam_kemp at apple.com>> wrote:
>> On Oct 30, 2017, at 10:57 AM, Mike Kluev <mike.kluev at gmail.com <mailto:mike.kluev at gmail.com>> wrote:
>> 
>> 
>> the new bucket would be "class and all of its extensions be them in the same file or in different files”.
> 
> That’s not a new bucket. It is equivalent to either internal or public, depending on whether you want to extend this beyond the module boundary. The set of code you would have to audit is the same.
> 
> it is different, see below:
> 
> === file: Some.swift
> 
> class Some {
>    internal func foo() {
>       bar()
>    }
>    classprivate func better() {
>       good()
>     }
> }
> 
> === file: Some+Bar.swift
> 
> extension Some {
>   internal func bar() {
>       foo()
>   }
>   classprivate func good() {
>       better()
>    }
> }
> 
> === any other file (same module)
> 
> class Other {
>     func x() {
>         let some = Some()
> 
>         some.foo() // ************** UNWANTED!!!!!!
>         
>         some.better() // error.  ****** WANTED!
>     }
> }

How do you know there’s not an extension in this file without looking? If you don’t know then you have to check. That puts it in the same bucket as internal or public. The set of files you have to search through for usages is the same.

> 
> I do not want to audit the class Other when I make a change to "foo" or "bar", which are essentially "private" and only made "internal" because of the language limitation in regards to "private" vs "multi-file class" issue.
> 
> 
> What does marking a method as “specialprivate” (my made up name for this new access level) tell clients about who can use it or how it can be used?
> 
> it tells them: "you can't use this, unless you are writing an extension to this class or making changes to this class itself”

There’s nothing special about an extension. Anyone can write an extension to any class. You shouldn’t need any special privileges to enable people to write extensions. You’re not gaining anything by introducing an interface only usable by extensions.

> 
> Mike
> 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171030/5953d307/attachment.html>


More information about the swift-evolution mailing list