[swift-evolution] [Discussion] fileprivate vs. private(file)
Joanna Carter
joanna at carterconsulting.org.uk
Mon Feb 20 07:21:29 CST 2017
> Perhaps 'type' access is 'set' level unless explicitly exposed:
> private(get: file, set: scope, type: module)
In a word - Yikes! Why on earth do access modifiers have to be sooo complicated?
I have written absolutely massive frameworks in C# with nothing but :
public - Access is not restricted.
protected - Access is limited to the containing class or types derived from the containing class.
internal - Access is limited to the current assembly.
protected internal - Access is limited to the current assembly or types derived from the containing class.
private - Access is limited to the containing type.
None of these levels are file-based and inexperienced developers coming onstream take very little time to understand what they mean and use them correctly.
I get the feeling some people are saying that Swift should not copy other languages because… well because it's Swift :-(
Then there's the extension to that, that access control should only be file-based. But, as I have already pointed out several times, this can very quickly lead to file bloat due to developers trying to gain privileged access to a type, but not being able to extend that type outside of the file.
> This still seems a bit clunky to me if you have a public and a private on
> the same line, but perhaps someone can suggest something for that.
But we already have such a syntax :
{
public private(set) var name: String
…
}
Clear, concise and easily read.
--
Joanna Carter
Carter Consulting
More information about the swift-evolution
mailing list