[swift-evolution] [Review] SE-0169: Improve Interaction Between private Declarations and Extensions

David Waite david at alkaline-solutions.com
Tue Apr 11 12:14:16 CDT 2017

On Apr 9, 2017, at 7:04 PM, Jose Cheyo Jimenez via swift-evolution <swift-evolution at swift.org> wrote:
> On Apr 8, 2017, at 5:19 AM, Neil via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> I agreed with Charlie, but I think there’s another option. 
>> The access control problems that both SE-0159 and SE-0169 are attempting to address can be resolved not by changing the definition of the existing access modifiers, but refocussing the use of extensions. 
>> One such way would be to introduce a `partial` modifier. It would be similar to C#’s partial modifier. The proposed partial modifier would be purely additive and it would go a long way to mitigate the access control issues inherent in extension-oriented design. 
>> The key characteristics of partial-oriented design would be:
>> - Partials would allow the splitting of implementations into multiple logical units without the same-file restriction.
> I really like the idea of partial but it would need to be restricted to the same file. This would allow partial to just be a compile time feature which just zips up a type together.  Another great feature would be that it could allow stored properties because it is only a compile time feature. Partial could be used to communicate to the user that this type has additional members and properties declared somewhere else in the file. 
> +1 for file scope partial. 

Partials from a C# sense only really shine when they are cross-file, same module. Then, preprocessing rules can turn something like a language description, XML-based language or extended HTML markup into property definitions and template rendering code. A type is partially user code, partially generated code.

Other languages may support this via the preprocessor-generated code being a super type or subtype of the user code type, but then you necessarily aren’t a peer - either a super type preprocessor class can’t see the user methods to hook in things like actions and actions, or the user class can’t access properties and methods declared by the preprocessor. In both cases, the root type usually winds up being declared abstract.

I don’t know what a same-file partial would be, other than an extension which also contributes to storage requirements of the type.

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

More information about the swift-evolution mailing list