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

Xiaodi Wu xiaodi.wu at gmail.com
Sat Mar 25 00:50:12 CDT 2017


On Sat, Mar 25, 2017 at 12:26 AM, Drew Crawford <drew at sealedabstract.com>
wrote:

>
>
>
> On March 24, 2017 at 11:20:59 PM, Jonathan Hull (jhull at gbis.com) wrote:
>
> You were the one who said redundancy was a *goal* of swift, which it is
> not.
>
> You misunderstand.  I'm arguing that the design of Swift is to have
> concept pairs – private/fileprivate, class/struct, let/var – in which one
> element of the pair is a superset of the other.  That is: we could convert
> a let/var program to use only var, we could convert a private/fileprivate
> program to use only fileprivate, etc., and yet we stubbornly persist to
> have all these keywords.
>
Again, this is deliberately ignoring the points made above. As we discussed
with dispatch models, speed is a key goal of Swift, and `let` vs `var`
offers optimization opportunities for the compiler. I've never heard of
anyone proposing that the design of Swift is based around concept pairs.
Nor are those you listed pairs of anything: `private` and `fileprivate` are
two of five access levels; there are not only classes and structs but also
enums and tuples; `let` and `var` will shortly be joined by `inout` and
`shared`, etc. Neither two, nor four, nor five are magic numbers. The
question is, how many of whatever it is we're considering hold their own
weight. The argument here is that new `private` does not.

This property has been labeled "redundancy" by people who dislike it.  I'm
> saying that whatever unkind name we decide to call it, it's a Swiftism, and
> we embraced it a long time ago.
>
What is "this property" that you claim to be a "Swiftism"?

Perhaps I just do not understand your argument, but it seems to be
>
> In your examples above, Swift is projecting a system image which is much
> simpler than the underlying concepts... For access controls, the user is
> being presented with the full complexity of that choice directly.
>
> This seems simply inaccurate to me.  For example, I am the top search
> result for "swift struct or class" and my explanation is 27 pages.
> Admittedly I am an insufferably longwinded writer who can't find the delete
> key, but for whatever reason Google seems to think my explanation is
> helpful to people struggling with that topic.
>
So indeed, Swift presents an apparently simple distinction with some very
complex underlying implications, since an explanation of it all can fill 27
pages.

While it is true that access control presents users the "the full
> complexity of that choice directly", this is because the choice is not
> actually complex.  One keyword is visible to a file and the other to a
> scope.  I could not produce 27 pages on that topic.
>
I am quite certain that we have filled many more than 27 pages on that
topic here. If you want to collate it into a didactic format you can start
with the delightful explanation of why ```private extension Foo { }```
works the way it does.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20170325/1283f605/attachment.html>


More information about the swift-evolution mailing list