[swift-evolution] Any consideration for directoryprivate as a compliment to fileprivate?

Jeremy Pereira jeremy.j.pereira at googlemail.com
Thu Dec 8 11:32:44 CST 2016


> On 8 Dec 2016, at 12:52, Aron Lindberg via swift-evolution <swift-evolution at swift.org> wrote:
> 
> I realise the general opinion here seems to be that we don't want any more changes to the access modifiers and I can understand why, but please take a look at the use case below:
> 
> "fileprivate" is needed for certain things like Equatable since the equatable function might need to know about private properties in a class. Lets say I have two structs:
> 
> struct A {
> ...
> }
> 
> struct B {
> ...
> }
> 
> Both are rather big so I declare each in a separate file (File A, File B), but I need to implement an equals function between these two structs that need access to private properties in both structs. This leaves me with two options:
> 
> a) Move the two structs into one file and use fileprivate and implement the equals function here. The result is one long messy file.
> b) Move the two files into a separate module and use "internal" for the variables I need acces to. This feels like overkill and struct A/B might have dependencies that make this inconvenient.
> 
> Am I missing a more optimal solution here? 

To conform to Equatable, the arguments to == need to have the same type.

However there might be other operators for which you might conceivably want to do this. I think the right long term answer to this is submodules and submodule visibility. For the present, I would argue that a source file isn’t messy just because it is long. So I’d put them in the same file or raise the read visibility of the properties the operator depends on to internal.




More information about the swift-evolution mailing list