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

Riley Testut rileytestut at gmail.com
Mon Apr 17 14:18:57 CDT 2017


> You’re right, I overgeneralized. Let me correct myself:
> 
> From what I’ve seen so far [*], using extensions for "code organization" often results in spaghetti code.
> 
> [*] Observed as a contractor; iOS platform; average Joe's code.


Fair :-)

Another use case for extensions I had forgotten about that I have used extensively, however, is using to group private or public members together, and have the access control level of the extension apply to each member in the extension (by default). Typically, I’ll declare the properties and initializers in the main type declaration, and then all public methods I’ll place in a “public” extension, and all private methods I’ll place in a “private” extension. This IMO is a great win for code readability, and another thing that I have lost the ability to do without using file private.

> On Apr 17, 2017, at 1:04 AM, Rudolf Adamkovič <salutis at me.com> wrote:
> 
> On 17 Apr 2017, at 01:46, Riley Testut <rileytestut at gmail.com> wrote:
>> 
>> So while you personally may not use extensions, calling the use of them "spaghetti code" is rather misguided IMO.
> 
> You’re right, I overgeneralized. Let me correct myself:
> 
> From what I’ve seen so far [*], using extensions for "code organization" often results in spaghetti code.
> 
> [*] Observed as a contractor; iOS platform; average Joe's code.
> 
> Thanks!
> 
> R+
> 



More information about the swift-evolution mailing list