[swift-evolution] final + lazy + fileprivate modifiers

Michel Fortin michel.fortin at michelf.ca
Sun Feb 12 14:14:50 CST 2017


Le 12 févr. 2017 à 12:24, Chris Lattner via swift-evolution <swift-evolution at swift.org> a écrit :
> 
> On Feb 12, 2017, at 8:19 AM, David Hart via swift-evolution <swift-evolution at swift.org> wrote:
>> Fileprivate 
>> 
>> I started the discussion early during the Swift 4 timeframe that I regret the change in Swift 3 which introduced a scoped private keyword. For me, it's not worth the increase in complexity in access modifiers. I was very happy with the file-scope of Swift pre-3. When discussing that, Chris Latner mentioned we'd have to wait for Phase 2 to re-discuss it and also show proof that people mostly used 'fileprivate' and not the new 'private' modifier as proof if we want the proposal to have any weight. Does anybody have a good idea for compiling stats from GitHub on this subject? First of all, I've always found the GitHub Search quite bad and don't know how much it can be trusted. Secondly, because 'private' in Swift 2 and 3 have different meanings, a simple textual search might get us wrong results if we don't find a way to filter on Swift 3 code.
> 
> I would still like to re-evaluate fileprivate based on information in the field.  The theory of the SE-0025 (https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md) was that the fileprivate keyword would be used infrequently: this means that it would uglify very little code and when it occurred, it would carry meaning and significance.

The following is only anecdotal of course. In my code base I went to the trouble of changing everything that could to `private`. I find I have to use `fileprivate` 21% of the time: 105 occurrences of fileprivate, 387 for private.

`fileprivate` is often necessary because I have a tendency to separate various parts of the code related to a type in multiple thematic extensions in the same file. Often there is one extension per protocol conformance, keeping the conformance declaration close to the implementation. And in many cases the implementation in the extension needs access to private details of the type, which requires `fileprivate`. 

I also have cases where the extension is rather pointless and would be better if merged into the base type. Those often require `fileprivate` too. Cleaning that up is very low priority though, so `fileprivate` remains.

I guess that makes one data point.

-- 
Michel Fortin
https://michelf.ca



More information about the swift-evolution mailing list