[swift-evolution] Pitch: Partial Implementations
swift-evolution at haravikk.me
Fri Mar 24 04:50:45 CDT 2017
> On 23 Mar 2017, at 21:10, Vladimir.S via swift-evolution <swift-evolution at swift.org> wrote:
> On 23.03.2017 21:21, Matthew Johnson via swift-evolution wrote:
>>> On Mar 23, 2017, at 1:12 PM, Charles Srstka via swift-evolution
>>> <swift-evolution at swift.org> wrote:
>>> In current Swift, a pattern has emerged among some developers, in
>>> order to logically group parts of a class or struct’s declaration,
>>> particularly around protocols:
> >> ...
>>> What do you think?
>> If we wanted to allow code like this to be written we wouldn’t need a
>> new keyword to do it. You are proposing two things here:
>> 1) Allow stored properties in same-module extensions. This has been
>> discussed in the past and is a possibility, but I suspect it is not in
>> scope for consideration during Swift 4.
> Are we really expect to have stored properties in same-module extensions?
> As I remember, there a lot of questions were raised during discussions so for some reason *I* had a feeling that we should not expect this happens in near feature. Probably I missed something.
I can see why some people might want to do stored properties in extensions to structure things, but personally I quite like the lack of flexibility as it encourages the initial type declaration to focus on what a type contains, while extensions focus on what it does. I've really taken to that style, as I now almost never declare methods or computed properties in an initial type declaration, unless it's a very simple one; instead doing all my methods and protocol conformances in their own extensions.
i.e- I quite like that by the time you've finished your type declaration you have finalised what its size will be, and nothing else can change that, spreading it out feels like it could make that more confusing. It also IMO helps to encourage you to keep a type's contents fairly simple, as you can see in one place if you've made it very complicated.
I suppose there's an argument for having the freedom to do it however you want, but I don't think spreading out across a module is a good idea; unless we're assuming that module in this context applies like in other proposals, where fileprivate is a "module" with only one file.
I dunno, I just think that as a pattern the current requirement to keep stored properties within a type declaration enforces some good practices. I found it a bit jarring at first too, but after adapting to the type + extensions style I find I actually really like doing things that way.
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution