[swift-evolution] [swift-evolution-announce] [Review] SE-0159: Fix Private Access Levels

Matthew Johnson matthew at anandabits.com
Thu Mar 23 20:35:34 CDT 2017



Sent from my iPad

> On Mar 23, 2017, at 8:27 PM, Drew Crawford <drew at sealedabstract.com> wrote:
> 
> 
> 
> 
> Sent from my iPhone
> On Mar 23, 2017, at 6:41 PM, David Hart <david at hartbit.com> wrote:
> 
>> I have difficulties imagining a submodule proposal that could allow us to eliminate fileprivate. Care to give an example?
> 
> The obvious example would be Rust.  Rust has exactly two visibilities, and merely one keyword.  By default, members are "private" which is visible inside the module (so, like Swift's internal). The "public" keyword is similar to Swift. 
> 
> The reason this works is that unlike in Swift where a module is something like a library or framework (Rust calls those "crates"), in Rust modules in are (explicitly) lexically scoped; a "mod myscope {}" module can be created for the portion of the file for which the member should be visible and it won't be visible outside that scope. Likewise, "fileprivate" can be achieved by enclosing the file in a "mod MyFile {}". And like all lexical scopes, they can be recursively nested to arbitrary depth to achieve any number of visibility behaviors (e.g., declare a module for the first half of two files) that would require complex new keywords to achieve in Swift. Finally there are some shortcut features like the ability to infer a module structure from the file system. 

This is a good example of what I meant.  There is an extremely broad range of possible designs for submodules.  Some of them, such as this example, would make it relatively easy to get by without fileprivate.  There are also many other possible designs that would not.  

We do not have any idea where Swift will end up yet.  It's not reasonable to make any assumptions about what use cases the eventual design might or might not address.

> 
> 
> 
> In Swift, modules are presently tied to libraries/frameworks in a 1:1 way. Because of this we lack the flexibility of recursively nestable modules of other languages and this is the underlying problem that motivates both scoped/private and fileprivate.  If we fixed that, we would actually not need either keyword. 
> 
> http://rustbyexample.com/mod/visibility.html
> https://doc.rust-lang.org/book/crates-and-modules.html
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170323/bae91847/attachment.html>


More information about the swift-evolution mailing list