[swift-evolution] classprivate protection level?
Adam Kemp
adam_kemp at apple.com
Mon Oct 30 19:11:18 CDT 2017
> On Oct 30, 2017, at 4:31 PM, Mike Kluev <mike.kluev at gmail.com> wrote:
>
> On 30 October 2017 at 23:14, Adam Kemp <adam_kemp at apple.com <mailto:adam_kemp at apple.com>> wrote:
>
> > On Oct 30, 2017, at 4:10 PM, Mike Kluev <mike.kluev at gmail.com <mailto:mike.kluev at gmail.com>> wrote:
> >
> > "classprivate" helps to resolve this problem. if it is marked so developer will at least think twice before making an extension to use it
>
> Why would they think twice, though? You’ve told them extensions can use it, and they’ve written an extension to use it. What did they do wrong? I don’t think the rules are nearly as clear as for protected.
>
> this is obvious: when they are writing a method in their own class and try to call: some.foo() it will give them and access level error (or even before that the autocomplete will not work as an early hint),
This is not the situation I was asking about. I was asking why would someone in a random file who is about to write an extension think twice about using this method? He wouldn’t, because you’ve told him using that method (in an extension) is fine. But you may not know about or approve of that code he’s writing, and you may later make a change that breaks that usage. The access level has not improved your ability to reason about what might break.
The root of our disagreement is in how we view extensions. There’s no real difference between code in an extension and code in some other class/struct/whatever. It’s still a client of the original class, not part of that class itself. It’s a separate thing. You’re thinking of an extension as part of the original class, but it’s not. Since anyone can write an extension, even in other modules, it has to be thought of as a separate thing, an external client. The author of the class has no control over or knowledge of extensions on that class, and the only way to be able to reason about whether a change to an API is safe is to use access levels that tell the author which files might be able to use that API.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20171030/6affb027/attachment.html>
More information about the swift-evolution
mailing list