[swift-evolution] access control proposal

Ilya Belenkiy ilya.belenkiy at gmail.com
Mon Dec 14 11:45:53 CST 2015


If something is not an implementation detail and should be shared, local
doesn't apply. This applies equally to types and extensions. Subclasses may
or may not need access to the internals of a class. If the class can share
those implementation details, they should not be local (really called
private in many other languages). But they can and should be hidden most of
the time -- it's just part of designing a good APIs that implementations
hide behind small, focused, and convenient interfaces. Local will help
enforce it.

--
Ilya Belenkiy

On Mon, Dec 14, 2015 at 12:17 PM David Owens II <david at owensd.io> wrote:

>
> On Dec 14, 2015, at 8:58 AM, Matthew Johnson <matthew at anandabits.com>
> wrote:
>
> I agree that you can concoct arbitrarily complex scenarios and a line must
> be drawn somewhere.  IMO the best place to draw the line is when you start
> considering something that is not super straightforward to explain and is
> not a natural extension of the obviously necessary access modifiers.
>
> IMO ‘scope’ passes this test and all of the complex counter-examples do
> not.  It is the logical conclusion of a simple narrowing of visibility from
> “everyone” to “module” to “file” to “scope”.  It is simple to explain and
> understand.  Those who don’t like it don’t need to use it.  Anything more
> complex is unlikely to pass such a test.
>
>
> I think the simplest counter-example is your own example for extensions.
> Each extensions will need access to different internals of the the type
> it’s applied to. So when it comes time to add that extension, you’ll be
> forced to promote the access control from “local” to “private”.
>
> Another straight-forward one is a subclass. Since “local” would be “scope”
> based, a subclass would also knot have access to those members defined as
> local in the super class, so they’d have to be promoted to private and thus
> available to all code within the file.
>
> I think “local” fits this definition:
>
> IMO the best place to draw the line is when you start considering
> something that is not super straightforward to explain and is not a natural
> extension of the obviously necessary access modifiers.
>
>
> It’s not an obviously necessary modifier as it’s usage is extremely
> limited and requires to be bounced up a level is a lot of design
> considerations, such as extensions and subclasses. There are certainly
> times where “local” could be used, but my opinion is that it’s not worth
> complexity for the limited value that it actually brings to the table.
>
> -David
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20151214/ee81efb5/attachment.html>


More information about the swift-evolution mailing list