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

Ross O'Brien narrativium+swift at gmail.com
Tue Mar 15 06:02:06 CDT 2016


Thoughts:
Here are the first two ideas I had regarding generic 'access' symbols.

"public" -> symbol visible outside the current module
"internal" -> symbol visible within the current module
"restricted" -> symbol visible within the current file
"private" -> symbol visible within the current declaration

"public" -> symbol visible outside the current module
"internal" -> symbol visible within the current module
"private" -> symbol visible within the current file
"intimate" -> symbol visible within the current declaration

However, I think if we're going to be 'Swift' about this, the terminology
should be more explicit about what the access level refers to, rather than
where it ranks on the accessibility scale. So, I'd prefer to see something
like:
"publicaccess" -> symbol visible outside the current module
"moduleaccess" -> symbol visible within the current module
"fileaccess" -> symbol visible within the current file
"declarationaccess" -> symbol visible within the current declaration

("private(module)", "private(file)", "private(declaration)" etc. works for
me too.)

This is clear. A "fileaccess" property can't be accessed outside its file,
there's on wondering about whether one term is subjectively more or less
restrictive than another term on the scale, and there's still room to
expand this to include "submodule" or C#-like "region" scopes if those are
desired future directions.


On Tue, Mar 15, 2016 at 10:43 AM, Thorsten Seitz via swift-evolution <
swift-evolution at swift.org> wrote:

> +1 for your proposed changes to private(set) etc.
>
> -Thorsten
>
>
> Am 15. März 2016 um 05:38 schrieb Shawn Erickson via swift-evolution <
> swift-evolution at swift.org>:
>
>
>
> On Mon, Mar 14, 2016 at 5:18 PM Chris Lattner via swift-evolution <
> swift-evolution at swift.org> wrote:
>
>> 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).
>>
>
> More thinking out loud...
>
> `public` -> exported from module
> <omitted> -> module scoped (e.g. current internal)
> `private` -> class, struct, etc. scoped (e.g. new private)
> `private(file)` or `file` -> file scoped (e.g existing private)
> `private(module)` or `module` or `internal` -> module scoped (e.g. current
> internal)
>
> public var foo = 0 // marks default getter and setter public
>
> public var foo = 0 {  // marks default getter and setter public however...
>   private set         // marks default setter private
> }
>
> var foo = 0 { // marks default getter and setter module scoped however...
>   public get  // marks default getter public
>   private set // marks default setter private
> }
>
> public var foo: Int { ... } // marks provided getter public, read-only
>
> var foo: Int {        // marks provided getter and setter module scoped
> however...
>   public get { ... }  // marks provided getter public
>   private set { ... } // marks provided setter private
> }
>
> public var foo: Int { // marks provided getter and setter public however...
>   get { ... }         // not specified, inherit access level public
>   private set { ... } // marks provided setter private
> }
>
> var foo: Int {        // marks provided getter and setter module scoped
> however...
>   get { ... }         // not specified, inherit access level module scoped
>   private set { ... } // marks provided setter private
> }
>
> private(module) var foo: Int { // marks provided getter and setter module
> scoped however...
>   get { ... }                 // not specified, inherit access level
> module scoped
>   private(file) set { ... }   // marks provided setter file scoped
> }
>
> var foo: Int {                // marks provided getter and setter module
> scoped however...
>   private(file) get { ... }   // not specified, inherit access level
> module scoped
>   private set { ... }         // marks provided setter file scoped
> }
>
> ...etc...
>
> public subscript(index: Int) -> Int { ... } // marks provided getter
> public, read-only
>
> public subscript(index: Int) -> Int { // marks provided getter and setter
> public
>   get { ... }                         // not specified, inherit access
> level public
>   set { ... }                         // not specified, inherit access
> level public
> }
>
> public subscript(index: Int) -> Int { // marks provided getter and setter
> public however...
>   get { ... }                         // not specified, inherit access
> level public
>   private set { ... }                 // marks provided setter private
> }
>
> subscript(index: Int) -> Int {  // marks provided getter and setter module
> scoped however...
>   get { ... }                   // not specified, inherit access level
> module scoped
>   private set { ... }           // marks provided setter private
> }
>
> subscript(index: Int) -> Int {  // marks provided getter and setter module
> scoped however...
>   public get { ... }            // marks provided getter public
>   private set { ... }           // marks provided setter private
> }
>
> subscript(index: Int) -> Int {  // marks provided getter and setter module
> scoped however...
>   public get { ... }            // marks provided getter public
>   private(file) set { ... }     // marks provided setter file scoped
> }
> ...etc...
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160315/34770183/attachment.html>


More information about the swift-evolution mailing list