[swift-evolution] [Review] SE-0159: Fix Private Access Levels
Matthew Johnson
matthew at anandabits.com
Sun Mar 26 12:43:55 CDT 2017
Sent from my iPad
> On Mar 26, 2017, at 10:43 AM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
>
> This reaches the crux of the issue, doesn't it? The Swift 2 design for access modifiers does exactly what you reject: that design is based on the premise that it is wise for file organization to follow encapsulation.
It's always a gamble speculating about the premise of someone else's design. That said, if I had to guess I would imagine maybe it had as much to do with the legacy of C-family languages and header files as anything else.
>
> Now, afaik, the accepted rationale for "new private" was that there needed to be something _more_ to fill out that scheme. And here the argument is that it didn't really add much benefit but brought about more complexity.
>
> If, however, what you're saying is that you reject the whole idea behind "fileprivate" altogether, well...I don't know if making it possible to ignore file-based encapsulation was ever really on the menu.
I'm not saying I reject the idea of file scopes at all. There are submodule designs that would make file scopes redundant, but that is as far as I've gone. We certainly need it in Swift 4 where we won't have submodules at all.
However, if the community strongly desires a change to remove one of the access modifiers I do think we should explore submodule designs that would fill the use cases for file scope and perhaps allow us to eliminate that. This would obviously need to happen in a future release where that is in scope. That is why I've been arguing that we should not force churn on users now. We should wait until we are ready to address all problems related to access control and submodules more holistically.
It sounds like the comments in my reply to John may not have even clear to you. What I'm saying is that file scopes and submodules cannot replace scoped access without forcing a tradeoff between code organization and encapsulation. This is a tradeoff I don't want to be forced to make. If I choose encapsulation that would result in many more very small files (10s of lines) than I would like. Just as large files can make code difficult to navigate, too many very small files can also make code difficult to navigate and can result in a lot of thrashing between files.
It should be possible to place small types together in the same file without sacrificing encapsulation. It should also be possible to have a small helper type in the same file as the type it is supporting without sacrificing encapsulation. This requirement can only be met by scoped access or something very similar.
In fact, I very often use file scopes in conjunction with scopes access. `private` is used to encapsulate state which is crucial to preserving invariants, etc of a helper type and `fileprivate` is used to restrict visibility of the helper type to the current file.
>> On Sun, Mar 26, 2017 at 07:30 Matthew Johnson via swift-evolution <swift-evolution at swift.org> wrote:
>>
>>
>> Sent from my iPad
>>
>> On Mar 26, 2017, at 4:13 AM, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
>>
>>>> On Mar 26, 2017, at 4:27 AM, Goffredo Marocchi <panajev at gmail.com> wrote:
>>>> On 26 Mar 2017, at 06:54, John McCall via swift-evolution <swift-evolution at swift.org> wrote:
>>>>
>>>>>> On Mar 25, 2017, at 2:11 AM, Carl Brown1 via swift-evolution <swift-evolution at swift.org> wrote:
>>>>>> Yes, it would change my opinion of it. I wouldn't become a strong supporter because I don't see any value in it, but a rigorous proof that this proposal could not possibly introduce regressions to any existing codebases would change my opinion from "strongly against" to "doesn't matter to me, I'll stop arguing against it and go get my real work done".
>>>>>>
>>>>> Speaking just for myself, this was a key part of why I was attracted to this proposal: it seemed to me to be extremely unlikely to cause regressions in behavior. Even without any special behavior in the migrator, code will mostly work exactly as before: things that would have been invalid before will become valid, but not the other way around. The exception is that old-private declarations from scopes in the same file can now be found by lookups in different scopes (but still only within the same file). It should be quite straightforward for the migrator to detect when this has happened and report it as something for the programmer to look at. The proposal causes a small regression in functionality, in that there's no longer any way to protect scopes from accesses within the file, but (1) it's okay for Swift to be opinionated about file size and (2) it seems to me that a workable sub-module proposal should solve that more elegantly while simultaneously addressing the concerns of the people who dislike acknowledging the existence of files.
>>>>
>>>> The opinionated flag sometimes, like being Swifty, is being used to swath away disagreement, but opinions should be reasonable and pragmatic too... opinionated as "you will code this way and you will like it" seems hardly ideal too if abused constantly. Programming is a creative endeavour too.
>>>>
>>>> Also, removing a feature that is used and is useful because "maybe" a year or more away there could be a feature that may address the concerns of the people we are stripping away the current feature from seems quite harsh and unfriendly at best... not very logical either.
>>>
>>> Scoped-private is not some awesomely expressive feature. It's an access restriction. The "opinion" I'm talking about hardly prevents you from coding however you like. It's just this: organizing your code into smaller, more self-contained components separated by file is good practice anyway, and when you do that, Swift will let you enforce that each component is properly encapsulated.
>>
>> This does not address the case where we have a small helper type that is only 10s of lines long, is not visible outside the file, and encapsulates an important part of the implementation using scoped private. The whole file is usually only a couple hundred lines. This is not an excessively long file and already contains a single component that is presented to the rest of the program.
>>
>> Some designs of submodules might allow us to properly encapsulate everything but if that requires us to put a small helper type in a separate file that would be a very unfortunate and inflexible constraint on how we are able to organize our code.
>>
>> I don't want encapsulation concerns dictating how I physically organize my code. That is significant and unnecessary complexity if you ask me. It forces a tradeoff between desired physical organization and desired encapsulation. We should not force users to make this tradeoff.
>>
>>>
>>> John.
>>>
>>>>
>>>>>
>>>>> John.
>>>>>> -Carl
>>>>>>
>>>>>> <graycol.gif>Xiaodi Wu ---03/25/2017 12:33:55 AM---Would it change your opinion on the proposal? On Sat, Mar 25, 2017 at 12:10 AM, Carl Brown1 <Carl.Br
>>>>>>
>>>>>> From: Xiaodi Wu <xiaodi.wu at gmail.com>
>>>>>> To: Carl Brown1/US/IBM at IBM
>>>>>> Cc: Drew Crawford <drew at sealedabstract.com>, Jonathan Hull <jhull at gbis.com>, swift-evolution <swift-evolution at swift.org>
>>>>>> Date: 03/25/2017 12:33 AM
>>>>>> Subject: Re: [swift-evolution] [Review] SE-0159: Fix Private Access Levels
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> Would it change your opinion on the proposal?
>>>>>>
>>>>>>
>>>>>> On Sat, Mar 25, 2017 at 12:10 AM, Carl Brown1 <Carl.Brown1 at ibm.com> wrote:
>>>>>> I would very much like to see your proof that the resultant code is unchanged in an arbitrary codebase.
>>>>>>
>>>>>> -Carl
>>>>>>
>>>>>> <graycol.gif>Xiaodi Wu ---03/25/2017 12:01:26 AM---On Fri, Mar 24, 2017 at 11:55 PM, Carl Brown1 <Carl.Brown1 at ibm.com> wrote: > Maybe this is the core
>>>>>>
>>>>>> From: Xiaodi Wu <xiaodi.wu at gmail.com>
>>>>>> To: Carl Brown1/US/IBM at IBM
>>>>>> Cc: Drew Crawford <drew at sealedabstract.com>, Jonathan Hull <jhull at gbis.com>, swift-evolution <swift-evolution at swift.org>
>>>>>> Date: 03/25/2017 12:01 AM
>>>>>> Subject: Re: [swift-evolution] [Review] SE-0159: Fix Private Access Levels
>>>>>>
>>>>>>
>>>>>>
>>>>>> On Fri, Mar 24, 2017 at 11:55 PM, Carl Brown1 <Carl.Brown1 at ibm.com> wrote:
>>>>>> My point is that, in rolling back the specific portion of SE-0025, case-sensitive find-and-replace will be the trickiest thing in most codebases, save those that result in invalid redeclarations. The behavior of the resultant code is, unless I'm mistaken, provably unchanged.
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>>
>>>>>> _______________________________________________
>>>>>> 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
>>>
>>> _______________________________________________
>>> 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/20170326/5037d193/attachment.html>
More information about the swift-evolution
mailing list