[swift-evolution] [Proposal] Partial initializers
matthew at anandabits.com
Mon Jan 18 08:46:18 CST 2016
> On Jan 15, 2016, at 10:12 PM, David Owens II <david at owensd.io> wrote:
> I like the updates. I think the distinction between partial inits and init functions is extremely subtle. The only difference is that partial init can set `let` members, correct?
Hi David, glad you like the changes.
Yes, that is the only difference, aside from the declaration syntax. It would be better if we didn’t need two separate forms but either one would sacrifice desirable functionality.
Giving up the ability to initialize a `let` is unacceptable IMO. Giving up the ability to share code that initializes `var` properties with post-initialization callers is also undesirable.
I considered having only once concept and allowing it to be called post-initialization if it only initializes `var` properties but I don’t like that approach. The compiler wouldn’t be able to check intent at the site of declaration (i.e. an init func that attempts to assign to a `let`) and it wouldn’t be clear to users which partial initializers could be called post-initialization and which cannot.
That leaves us with the need for two very similar concepts. The only reasonable alternative seems to be dropping `init func`. I would do that it if it became a hurdle to accepting the proposal, but I think it will be a common use case and is worth including.
Do you have any further thoughts? Do you agree with the decision I made here?
> The only feedback I really have is that this makes the initialization rules even more complicated. I don't know how to address that though. =)
Agree, the rules are essential complexity if we want safe initialization.
I think the small incremental increase in complexity is a worthwhile price to pay for the ability to factor initialization code. This is especially true if we’re going to add stored properties in extensions. I wouldn’t want to see a situation where we could have partial initializers, but only when we move some properties into an extension.
I hope you agree.
>> On Jan 14, 2016, at 8:08 PM, Matthew Johnson via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> I have completed the second draft of my partial initializers proposal (the first really complete draft).
>> This proposal also includes some discussion of memberwise initialization at John McCall’s request. If anyone would like to continue discussing that topic informally I will be happy to do so, however any such discussion should happen on one of the existing memberwise initialization threads or on a new thread related to that topic. Please do not let that section of the document be a distraction from the partial initializer proposal itself.
>> The new draft can be found here:
>> https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md <https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md>
>> I really appreciate any feedback you have!
>> swift-evolution mailing list
>> swift-evolution at swift.org <mailto:swift-evolution at swift.org>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the swift-evolution