<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div><br><br>Sent from my iPad</div><div><br>On Jan 11, 2016, at 10:33 PM, David Owens II <<a href="mailto:david@owensd.io">david@owensd.io</a>> wrote:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 11, 2016, at 5:43 PM, Matthew Johnson <<a href="mailto:matthew@anandabits.com" class="">matthew@anandabits.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><meta http-equiv="Content-Type" content="text/html charset=utf-8" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Jan 11, 2016, at 7:33 PM, David Owens II <<a href="mailto:david@owensd.io" class="">david@owensd.io</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><div class=""><br class="Apple-interchange-newline">On Jan 10, 2016, at 7:44 PM, Matthew Johnson via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">I have always considered the Flexible Memberwise Initialization proposal to be just a first step (as evidenced by the many future enhancements it discussed). Its review has inspired new ideas and helped to shape my vision of the best long-term solution. My final thoughts about the review can be found here: <a href="https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/006176.html" class="">https://lists.swift.org/pipermail/swift-evolution/Week-of-Mon-20160104/006176.html</a></div><div class=""><br class=""></div><div class="">Partial initializers is the second in a series of three proposals describing general features that can work together to form a complete solution.</div><div class=""><br class=""></div><div class=""><div class="">The proposal drafts can be found at the following links:</div><div class=""><br class=""></div><div class="">* <b class="">Parameter forwarding:</b> <a href="https://github.com/anandabits/swift-evolution/blob/parameter-forwarding/proposals/NNNN-parameter-forwarding.md" class="">https://github.com/anandabits/swift-evolution/blob/parameter-forwarding/proposals/NNNN-parameter-forwarding.md</a></div><div class="">* <b class="">Partial initializers:</b> <a href="https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md" class="">https://github.com/anandabits/swift-evolution/blob/partial-initializers/proposals/NNNN-partial-initializers.md</a></div><div class="">* <b class="">Property lists:</b> <a href="https://github.com/anandabits/swift-evolution/blob/property-lists/proposals/NNNN-property-lists.md" class="">https://github.com/anandabits/swift-evolution/blob/property-lists/proposals/NNNN-property-lists.md</a></div></div><div class=""><br class=""></div></div></div></blockquote></div><br class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">The biggest drawback I see is that is doesn’t really address the ability to use normal functions to initialize the state of the type. For example, in order to implement a “reset” or “clear” mechanism, I still need to duplicate a bunch of init code.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><blockquote class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><font face="Menlo" class="">class CFoo {<br class=""> private(set) var value: Int<br class=""> <br class=""> func reset() {<br class=""> value = 0<br class=""> }<br class=""> <br class=""> init() {<br class=""> // Really want to just call this...<br class=""> //reset()<br class=""> <br class=""> // But, instead, I need to duplicate the code from `reset()`<br class=""> value = 0<br class=""> }<br class=""> <br class=""> func inc() {<br class=""> ++value<br class=""> }<br class="">}<br class=""><br class="">let c = CFoo()<br class="">c.inc()<br class="">c.value // 1<br class="">c.reset()<br class="">c.value // 0<br class=""></font><br class=""></div></blockquote><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">Take the above code, the “init” functionality is really about putting the type in the correct state. I think I’d rather see a mechanism to make a non-initializer as adhering to the rules of an init() so that it could be used in multiple contexts. </div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;">I think this modification makes your proposal much more interesting and applicable to more use cases.</div><div class="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"><br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">That is a fair point. </div><div class=""><br class=""></div><div class="">The reason I didn’t go that route has a lot to do with `let` properties. It would feel weird to me to be assigning to a `let` in a non-init method (that is why I didn’t like Joe’s tuple property idea). And a method that does that couldn’t be called any other time anyway.</div></div></div></div></blockquote><div><br class=""></div><div>Well, this is a limitation (assigning to lets) that convenience inits() have as well. Also, as it’s a function that is callable, it makes little sense to have `let` assignments in it anyway. So that limitation seems fine. The annotation would only be there to allow the compiler (and code authors) know that this method is intended to be allowed in the initialization rules, so some restrictions may apply.</div></div></div></blockquote><div><br></div>Right, but I do want to allow partial inits to write to a 'let'. That's why I went down the other path.<div><br><blockquote type="cite"><div><div><div><br class=""></div><blockquote type="cite" class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">Maybe we could introduce partial inits as well as an attribute or decl modifier for methods that have similar behavior to partial inits, but are not allowed to assign to a `let` property (maybe @init). I could add something along those lines to this proposal or it could be a separate follow-on proposal.</div><div class=""><br class=""></div><div class="">What do you think of that? </div></div></div></blockquote><br class=""></div><div>What I’m saying is that you don’t need the partial inits anymore, you still need some of your rules, but the actual “partial init” would be replaced by this modifier on functions.</div><div><br class=""></div><div>Maybe something like this:</div><div><br class=""></div><div><font face="Menlo" class=""> initializer func reset() {<br class=""> value1 = 0<br class=""> }</font><br class=""></div><div><br class=""></div><div>The “initializer” modifier would be your “partial init” modifier. For this to work though, you’d basically have to take the same limitation as convenience inits() today and disallow `let` values to be set. However, most of your other rules would apply to these.</div></div></blockquote><div><br></div>Exactly. That 'let' limitation is why I don't consider this approach sufficient.</div><div><br><blockquote type="cite"><div><div><br class=""></div><div>Well… I guess there is this too:</div><div><br class=""></div><div><div class=""><blockquote type="cite" class=""> Partial initializers receive an identifier, which avoids the need to rely on overloading to differentiate between partial initializers.</blockquote><br class=""></div><div class="">This would still remove the ability to use `let` assignments, but those functions could be allowed to be called like normal functions.</div><div class=""><br class=""></div></div><blockquote style="margin: 0 0 0 40px; border: none; padding: 0px;" class=""><div><div class=""><font face="Menlo" class="">struct S {</font></div></div><div><div class=""><font face="Menlo" class=""> let a, b, c, d: Int</font></div></div><div><div class=""><font face="Menlo" class=""> partial init bAndC(i: Int = 10) {</font></div></div><div><div class=""><font face="Menlo" class=""> b = 10</font></div></div><div><div class=""><font face="Menlo" class=""> c = 20</font></div></div><div><div class=""><font face="Menlo" class=""> }</font></div></div><div><div class=""><font face="Menlo" class=""> init(i: Int) {</font></div></div><div><div class=""><font face="Menlo" class=""> a = i * 2</font></div></div><div><div class=""><font face="Menlo" class=""> d = i * 4</font></div></div><div><div class=""><font face="Menlo" class=""> bAndC.init()</font></div></div><div><div class=""><font face="Menlo" class=""> }</font></div></div><div><div class=""><font face="Menlo" class="">}</font></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><font face="Menlo" class="">var s = S(12)</font></div><div class=""><font face="Menlo" class="">s.bAndC(1)</font></div></div></blockquote><div><br class=""></div><div>Again, you’ve have to remove the `let` assignments… </div></div></blockquote><div><br></div>Yes, I think allowing this makes sense as long as the partial init does not write to a 'let'. I have updated the proposal to allow for this. I will publish a new draft soon, hopefully later today.</div><div><br></div><div>Matthew</div><div><br><blockquote type="cite"><div><div><br class=""></div><div>Anyhow, just mostly thinking out loud at this point.</div></div></blockquote><div><br></div>No harm in that! I appreciate the feedback. That's why I shared it even though it was still an early draft.</div><div><br></div><div>Matthew</div><div><br><blockquote type="cite"><div><div><br class=""></div><div>-David</div><div><br class=""></div></div></blockquote></div></body></html>