[swift-evolution] Type-based ‘private’ access within a file
michel.fortin at michelf.ca
Wed Apr 5 07:13:58 CDT 2017
> 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`.
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.
> - Similarly, this simplifies access control for most people. Most people will now only care about private/internal/public. fileprivate will become an expert feature used in specific cases to solve a specific class of problems. Progressive disclosure of complexity is important.
People who only care about private/internal/public and ignore `fileprivate` will thus be restricted when it comes to using extensions on multiple types at the same time. If using `fileprivate`indeed becomes rare or discouraged, this will shape the language away from such patterns.
> - This design is true to the existing design of Swift: we want to encourage the implementation of types to be freely broken into extensions. This alignment with extension oriented programming was the one important virtue of the Swift 1/2 access control design that Swift 3 lost.
This cut both ways. We want to encourage the implementation of types being freely broken into extensions. Great!. But do we want to discourage features implemented as extensions that spans across multiple types?
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.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution