[swift-evolution] [Discussion] fileprivate vs. private(file)

Sean Heber sean at fifthace.com
Mon Feb 20 18:58:56 CST 2017


It might have been suggested (this discussion is huge), but I think private could just be defined more or less like a combination of Swift 3 fileprivate and private with one little twist - it is also accessible from extensions in other files internal to the defining module.

Module 1 File A.swift:

public class Foo {
  private var property: Int
}

class Bar {
  // a Foo's property could be accessible inside here
}

extension Foo {
  // property is accessible 
}


Module 1 File B.swift:

// a Foo's property is NOT accessible 

extension Foo {
  // property is accessible in internal extension
}


Module 2 File C.swift:

// a Foo's property is NOT accessible

extension Foo {
  // property is STILL NOT accessible here
}


l8r
Sean

Sent from my iPad

> On Feb 20, 2017, at 6:22 PM, Karl Wagner via swift-evolution <swift-evolution at swift.org> wrote:
> 
> 
>> On 21 Feb 2017, at 01:00, Xiaodi Wu via swift-evolution <swift-evolution at swift.org> wrote:
>> 
>> I'm terribly sorry to be _that guy_, but I have to interject that `private(file)` was discussed extensively during review for SE-0025, that the full scheme laid out in the first message of this thread was given consideration, and that the core team took these suggestions into account before accepting and implementing `fileprivate`.
>> 
>> Now, it has been said that real-world experience opens the door to reconsidering the substantive content of SE-0025 (as in, whether "new" private should exist at all). It has also long been said that a superior name would be considered instead of `fileprivate` if someone came up with one. But clearly, if hundreds of messages advocating for `private(file)` did not cause the core team to consider it to be a superior name, it is exceedingly poor form to keep bringing it up again. It's already exhausting to bikeshed upcoming features, but this shed has already shipped.
>> 
> 
> We are seeing lots of topics about access control in general. It’s clear people aren’t completely satisfied, but I don’t have a clear, coherent picture of what people dislike the most.
> 
> Personally, I just don’t like fileprivate, just like I didn’t like it’s ol’ pap, file-scoped “private”. Especially now we don’t have header files, I sometimes want to restrict access of a member to certain other types without making them exposed throughout the entire module (so the rest of my internal code is written in the closest thing to the client’s experience). At the same time, sticking everything in to one enormous file can sometimes be hard to manage - I end up with quarter-screens full of whitespace to act as visual separators.
> 
> I don’t know exactly what to suggest, but I feel we need to organise and answer the general grievances about access control and update the FAQ.
> 
> - Karl
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution


More information about the swift-evolution mailing list