So discussion of the exact naming convention for access modifiers has been
discussed multiple times, especially when fileprivate was being introduced.
It's now been a while since fileprivate was added, so we've all had more time
to actually work with it, so I wanted to raise the discussion again to see what
people now think.
Specifically, during the debate over access modifiers I really didn't like the
propose fileprivate, as I don't like conjoined lower-case key-"words" (to me a
keyword should always be a single word, I still don't like associatetype or
typealias either, and neither does macOS' auto-correct 😉). And to be honest my
opinion hasn't changed; if anything I hate it even more.
The proposal I preferred was to use only the public and private keywords and
use parameters to provide greater specificity, like so:
public as it is now
private(module) equivalent to internal, which is private to the current
module/project
private(file) equivalent to fileprivate
private(scope) equivalent to current private
The actual parameters are up for debate, but I still feel this a lot clearer. I
also generally prefer the parameterised version for several reasons:
Readability: I know not everyone will agree on this one, but I much prefer the
separation to having conjoined keywords.
Fewer Keywords: Maybe I'm a keyword purist or something, but I just don't like
having too many keywords in the language, especially four for what amounts to a
single feature (access).
Extensibility: It is easier and cleaner to add more parameters in future. For
example, private(type) could be an equivalent to protected access in other
languages. It can also be used to more easily group external extension
modifiers under public such as public(final), public(open) etc.
For setter-specific access it might look something like:
private(file:set) var someValue:Int = 0
I know it might not seem that important to some people, but this is one area of
Swift's syntax that still bothers me, perhaps unreasonably so, but I don't get
to pick what annoys me! I'd also seek to replace associatedtype and typealias
(and any other conjoined keyword I've forgotten) but I haven't thought of any
alternatives that I like for those yet.
Anyway, just wanted to discuss how others felt having used fileprivate and such
for a while, and whether it's worth revisiting, or if I just have to live with
it.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution