[swift-evolution] classprivate protection level?

Mike Kluev mike.kluev at gmail.com
Sun Oct 29 19:29:28 CDT 2017


On 29 October 2017 at 16:04, Adam Kemp <adam.kemp at apple.com> wrote:

> Internal is the right choice here. If it gives too much access then you
> might consider pulling this code into a separate module.
>
> If “private” gave access to every extension then any code outside your
> module could make a new extension and access that method. That would make
> it effectively public in that you wouldn’t have any ability to limit who
> can call it.
>
>
there are two very different use cases for which we use extensions.

1) the extensions i use to split implementation of my own classes into
different parts and / or files. for the sake of this discussion let's call
this type of extensions a "continuation".

2) the extensions that are used to extend other people classes or system
classes. this matches what we have now.

speaking of (1) the naïve newcomers from C++ land would consider these
continuations the same as splitting their C++ class implementation into
separate files. e.g. the expectation is having an ability to access
"private" members. if such a thing existed in swift at all it wouldn't be
unimaginable having an ability to add variables in these continuations the
same way as in the class itself. here  "protected" access level would be a
reasonable addition, and if we want to be totally nitpicky "protected"
would be for subclasses and some other keyword, say, "extensionprivate" or
"domestic" for continuations.

an interesting challenge would be somehow prohibiting external people
adding continuations to your own classes :)

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


More information about the swift-evolution mailing list