[swift-evolution] SE-0025: Scoped Access Level, next steps

David Ungar ungar at icloud.com
Tue Mar 15 13:05:34 CDT 2016


First post to Swift evolution, please bear with me: the following is a bit wild, but something to think about for the future, maybe.

Swift had three, and will now have four levels of scoping. In the future, might there be five? A scope that spans a limited set of modules, or a scope that only applies within a region of a declaration?
Maybe scope modifiers should be something like: scope(all), scope(module), scope(file), scope(declaration). 
In other words, something that says it is a scope declaration, followed by a noun that names what the scope is. If additional scopes are needed in the future, it might be easier to add them. For instance, if there’s a way to name a collection of modules, there could be a scope(module-collection-name) modifier.

Hope you enjoy this thought,

- David


> Per Doug’s email, the core team agrees we should make a change here, but would like some bikeshedding to happen on the replacement name for private.
> 
> To summarize the place we’d like to end up:
> 
> - “public” ->symbol visible outside the current module.
> - “internal” ->symbol visible within the current module.
> - unknown ->symbol visible within the current file.
> - “private” ->symbol visible within the current declaration (class, extension, etc).
> 
> The rationale here is that this aligns Swift with common art seen in other languages, and that many people using private today don’t *want* visibility out of their current declaration. It also encourages “extension oriented programming”, at least it will when some of the other restrictions on extensions are lifted. We discussed dropping the third one entirely, but think it *is* a useful and important level of access control, and when/if we ever get the ability to write unit tests inside of the file that defines the functionality, they will be a nicer solution to @testable.
> 
> The thing we need to know is what the spelling should be for the third one. Off hand, perhaps:
> 
> fileprivate
> private(file)
> internal(file)
> fileaccessible
> etc
> 
> Some other thoughts on the choice:
> - this will be a declaration modifier, so it will not “burn” a keyword.
> - if will be a uniquely Swift thing, so there is virtue in it being a googlable keyword.
> 
> Thoughts appreciated.
> 
> -Chris
> 
> 
> 


More information about the swift-evolution mailing list