[swift-evolution] Type-based ‘private’ access within a file

Víctor Pimentel vpimentel at tuenti.com
Wed Apr 5 09:56:30 CDT 2017


> El 5 abr 2017, a las 14:13, Michel Fortin via swift-evolution <swift-evolution at swift.org> escribió:
> 
>> Le 5 avr. 2017 à 0:02, Chris Lattner via swift-evolution <swift-evolution at swift.org> a écrit :
>> 
>>  - fileprivate should really become much more rare, which makes it more meaningful and significant where it occurs.  This was the original idea and intent behind SE-0025.
> 
> I think this will end up being a flawed assumption, just like last time.
> 
> Granted: there will be less need for `fileprivate` with this. Files that implement a type will not need `fileprivate` regardless of how many extensions they use to implement the type. But note that if there is only one type defined in that file (as is often the case), `private` has absolutely the same meaning as `fileprivate`.

Looking at my company's codebase that has thousands of `fileprivate` methods, with this proposal we will be able to revert all of them to `private`.

So yeah, it will have great impact for us, and we basically would not need to think about where to use `private` and `fileprivate` again. The important thing for us is that a `private` implementation detail is not exposed to other types.

So I don't think the assumption is as flawed as before, since we have much more real world data now.

> Files that extend multiple types for the purpose of implementing a particular feature will still require `fileprivate` if those extensions want to share some implementation details. Maybe we gain something by making this explicit with a special access level, but frankly I don't really see what those gains are.

While I would avoid those patterns, I understand that some people find value in them. However, I fail to understand why this proposal would harm such practices: wouldn't those extensions be written exactly as right now?

> I actually don't fear this will actually hamper this pattern much. People will just use `fileprivate` for these "rare" cases that actually aren't that rare. It's not that big of a problem. But that would mean the assumption is flawed.
> 
> On the other hand, if `fileprivate`effectively becomes a rarity, then it'll mean people are shying away from this pattern. In my opinion, that'd be unfortunate.

People that uses that pattern already have to write the word `fileprivate`, and it doesn't seem that it hasn't discouraged you from using it.

It certainly hasn't discouraged us to use the pattern that we considered better, even if we don't agree with the current keywords.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170405/9a1b99a5/attachment.html>


More information about the swift-evolution mailing list