[swift-evolution] [swift-evolution-announce] [Review] SE-0025 Scoped Access Level

Drew Crawford drew at sealedabstract.com
Fri Feb 26 21:44:00 CST 2016


> What is your evaluation of the proposal?
+0.9

> Is the problem being addressed significant enough to warrant a change to Swift?
Yes.  Let me defend that a little, since that seems to be the angle of criticism for this proposal.

Some propose that convention is good enough.  But the difference in safety between "convention" and "compile error" is stark.

Threading is one especially pernicious case.  If I have an ivar that is only safe for access from one thread, I *need* compiler enforcement.  I *need* a guarantee that this ivar is only accessed through public interface methods that can be audited to be threadsafe.  Simply a doccomment that says "bad programmer, don't do it" is not enough.

This is not even a matter of "artistic choice" of whether or not I want to follow "one file per class".  I can achieve thread safety with "private" ivars and "one file per class", but if my class is UITableViewCellContentView (which is an implementation detail that should be hidden even to most of UIKit) I am now forced to expose that implementation detail to my entire team.

This places me in the unconscionable situation of choosing between whether I have thread safety or encapsulation, between whether my coworker will accidentally create a threading bug or accidentally use a class they ought not to use and I am unable to appropriately hide.

ObjC has a solution to this problem: the "Foo-private.h".  Obviously I think that is not the right solution for Swift.  But to say it is not a significant problem is to be unfamiliar with the complexities of large ObjC codebases.  

> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
Personally, the solution I would prefer is Rust's "use" / "pub use" system.  (For an explanation on this accessible to Swift programmers, see here <http://faq.sealedabstract.com/rust/#visibility>.)  The key difference is that while Swift has a flat namespace for each module, in Rust, modules are recursively composeable.  So Rust's UIKit framework would consist of multiple "components", such as a UITableView component (with e.g. UITableView, UITableViewController, UITableViewCell, UITableViewCellContentView, etc.), UIText component (UITextField/UITextArea), UINotification component (UILocalNotification, UIUserNotificationAction, UIUserMutableNotificationAction), etc., where each component has identifiers that are private to the class, identifiers that are shared with only the component, identifiers that are internal to all of UIKit, and identifiers that are public to the application developer.

The advantage of the Rust system is that it can achieve in two access keywords what Swift achieves in four.  However, a change like that would be more controversial than the present proposal.  I support some progress on improving access modifiers, even if this is not my ideal solution.

> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
I've followed this from the earliest discussions.  I've rethought my position somewhat in response to the growing uncertainty about dropping the NS prefix, which I think exposes some very real problems with visibility in Swift.

As that situation has developed, I no longer believe this proposal goes far enough.  But it does go somewhere, and we should not stay where we are.

> On Feb 26, 2016, at 1:05 PM, Douglas Gregor <dgregor at apple.com> wrote:
> 
> Hello Swift community,
> 
> The review of SE-0025 “Scoped Access Level" begins now and runs through March 3, 2016. The proposal is available here:
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md <https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md>
> Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at
> 
> https://lists.swift.org/mailman/listinfo/swift-evolution <https://lists.swift.org/mailman/listinfo/swift-evolution>
> or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:
> 
> Proposal link:
> 
> https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md <https://github.com/apple/swift-evolution/blob/master/proposals/0025-scoped-access-level.md>
> Reply text
> 
> Other replies
>  <https://github.com/apple/swift-evolution#what-goes-into-a-review-1>What goes into a review?
> 
> The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:
> 
> What is your evaluation of the proposal?
> Is the problem being addressed significant enough to warrant a change to Swift?
> Does this proposal fit well with the feel and direction of Swift?
> If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?
> How much effort did you put into your review? A glance, a quick reading, or an in-depth study?
> More information about the Swift evolution process is available at
> 
> https://github.com/apple/swift-evolution/blob/master/process.md <https://github.com/apple/swift-evolution/blob/master/process.md>
> Thank you,
> 
> -Doug Gregor
> 
> Review Manager
> 
> _______________________________________________
> swift-evolution-announce mailing list
> swift-evolution-announce at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution-announce

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160226/a38b8277/attachment.html>


More information about the swift-evolution mailing list