<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Jan 8, 2016, at 2:40 PM, Wallacy 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 dir="ltr" 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="">I like the idea of the proposal (not 100%) but i really dislike the "Future enhancements" part:<br class=""><div class=""><br class=""></div><div class=""><u class="">@default</u><span class="Apple-converted-space"> </span>is unnecessary in my opinion, i think just write the "future" variable declaration ("memberwised") and put the default value is enough:</div><div class=""><br class=""></div><div class=""><pre style="overflow: auto; font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; margin-top: 0px; margin-bottom: 0px; line-height: 1.45; padding: 16px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; color: rgb(51, 51, 51); background-color: rgb(247, 247, 247);" class=""><span class="pl-k" style="color: rgb(167, 29, 93);">struct</span> S {
<span class="pl-k" style="color: rgb(167, 29, 93);">let</span> s: <span class="pl-c1" style="color: rgb(0, 134, 179);">String</span>
<span class="pl-k" style="color: rgb(167, 29, 93);">let</span> i: <span class="pl-c1" style="color: rgb(0, 134, 179);">Int</span>
<span class="pl-c" style="color: rgb(150, 152, 150);">// user declares:</span>
memberwise <span class="pl-k" style="color: rgb(167, 29, 93);">init</span>(<span style="font-size: 13.6px; line-height: 1.45;" class="">s: </span><span class="pl-c1" style="font-size: 13.6px; line-height: 1.45; color: rgb(0, 134, 179);">String</span><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span><span class="pl-k" style="font-size: 13.6px; line-height: 1.45; color: rgb(167, 29, 93);">=</span><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span><span class="pl-s" style="font-size: 13.6px; line-height: 1.45; color: rgb(24, 54, 145);"><span class="pl-pds" style="box-sizing: border-box;">"</span>hello<span class="pl-pds" style="box-sizing: border-box;">"</span></span><span style="font-size: 13.6px; line-height: 1.45;" class="">,</span><span class="pl-k" style="font-size: 13.6px; line-height: 1.45; color: rgb(167, 29, 93);">...</span><span style="font-size: 13.6px; line-height: 1.45;" class="">) {}</span></pre><pre style="overflow: auto; margin-top: 0px; margin-bottom: 0px; padding: 16px; border-top-left-radius: 3px; border-top-right-radius: 3px; border-bottom-right-radius: 3px; border-bottom-left-radius: 3px; word-wrap: normal; word-break: normal; background-color: rgb(247, 247, 247);" class=""><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span></font><span class="pl-c" style="color: rgb(150, 152, 150); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">// compiler synthesizes:</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">
</span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">init</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">(s: </span></font><span class="pl-c1" style="color: rgb(0, 134, 179); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">String</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">=</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span></font><span class="pl-s" style="color: rgb(24, 54, 145); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;"><span class="pl-pds" style="box-sizing: border-box;">"</span>hello<span class="pl-pds" style="box-sizing: border-box;">"</span></span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">, i: </span></font><span class="pl-c1" style="color: rgb(0, 134, 179); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">Int</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">) { </span></font><span style="color: rgb(150, 152, 150); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;" class="">// because s: </span><font color="#969896" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 19.72px;" class="">String matches the sintaxe, so the compiler will not (re)synthesize.</span></font><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">
</span></font><span class="pl-c" style="color: rgb(150, 152, 150); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">/* synthesized */</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">self</span><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">.</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">s </span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">=</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> s
</span></font><span class="pl-c" style="color: rgb(150, 152, 150); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">/* synthesized */</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> </span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">self</span><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">.</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class="">i </span></font><span class="pl-k" style="color: rgb(167, 29, 93); font-family: Consolas, 'Liberation Mono', Menlo, Courier, monospace; font-size: 13.6px; line-height: 1.45;">=</span><font color="#333333" face="Consolas, Liberation Mono, Menlo, Courier, monospace" class=""><span style="font-size: 13.6px; line-height: 1.45;" class=""> i
}
}</span></font></pre></div><div class=""><br class=""></div><div class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>This is not allowed under the proposal. If you declare a parameter with an external label matching a synthesized parameter an error will result. Allowing it would be one way to solve the default for `let` problem but it would require duplicating the parameter declaration and default value in every memberwise init.</div><br class=""><blockquote type="cite" class=""><div class=""><div dir="ltr" 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=""><div class=""><u class="">memberwise properties</u><span class="Apple-converted-space"> </span>and<span class="Apple-converted-space"> </span><u class="">@nomemberwise</u><span class="Apple-converted-space"> </span>are too much trouble for little gain. Hand write the init by itself will be more easy and clear.<br class=""></div><div class=""><br class=""></div><div class="">The fist part when the proposal focuses only on the automation of (maybe only undeclared) variables on init using "..." placeholder as insertion point, I believe that can be a nice feature.<br class=""></div><div class=""><br class=""></div></div><br 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=""><div class="gmail_quote" 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 dir="ltr" class="">Em sex, 8 de jan de 2016 às 18:13, Thorsten Seitz via swift-evolution <<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>> escreveu:<br class=""></div><blockquote class="gmail_quote" style="margin: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: solid; padding-left: 1ex;"><div style="word-wrap: break-word;" class=""><div class=""><blockquote type="cite" class=""><div class="">Am 08.01.2016 um 19:58 schrieb Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>>:</div><br class=""><div class=""><div class=""><div class="">On Fri, Jan 8, 2016, at 12:56 AM, Thorsten Seitz wrote:<br class=""></div><blockquote type="cite" class=""><div class=""> </div><div class=""><blockquote type="cite" class=""><div class="">Am 08.01.2016 um 00:41 schrieb Kevin Ballard via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>>:<br class=""></div><div class=""> </div><div class=""><div class=""><div class="">On Thu, Jan 7, 2016, at 03:11 PM, Matthew Johnson wrote:<br class=""></div><blockquote type="cite" class=""><div class=""> </div><div class=""><blockquote type="cite" class=""><div class="">On Jan 7, 2016, at 3:31 PM, Kevin Ballard <<a href="mailto:kevin@sb.org" target="_blank" class="">kevin@sb.org</a>> wrote:<br class=""></div><div class=""> </div><div class=""><div class=""><div class="">On Thu, Jan 7, 2016, at 07:12 AM, Matthew Johnson wrote:<br class=""></div><blockquote type="cite" class=""><div class=""><div class="">Do you have an example of where you would want a caller to initialize a property, but then overwrite the value they provide<span class="Apple-converted-space"> </span><b class="">during initialization</b>?<br class=""></div></div></blockquote><div class=""> </div><div class="">Sure, how about something like a Rect type that always guarantees it's in "standard" form (e.g. no negative sizes):<br class=""></div><div class=""> </div><div class="">struct StandardRect {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>var origin: CGPoint<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>var size: CGSize {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>didSet {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>// ensure standardized form here<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>}<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>}<br class=""></div><div class=""> </div><div class=""> <span class="Apple-converted-space"> </span>memberwise init(...) {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>if size.width < 0 {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>origin.x += size.width<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>size.width = -size.width<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>}<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>if size.height < 0 {<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>origin.y += size.height<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>size.height = -size.height<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>}<br class=""></div><div class=""> <span class="Apple-converted-space"> </span>}<br class=""></div><div class="">}<br class=""></div></div></div></blockquote><div class=""> </div><div class="">This is a good example. Thanks! <br class=""></div></div></blockquote></div></div></blockquote><div class=""> </div><div class="">Actually I do not like this example for several reasons: (1) I would make the rectangle an immutable type with let properties, (2) the didSet already seems to do what is encoded in the memberwise init, so this seems to be redundant, (3) the memberwise init is so complex that having the automatic initialization feature is not really worth it for this example, especially as it seems to require using var properties instead of let properties to do the overwriting.<br class=""></div></div></blockquote><div class=""> </div><div class="">1) Why would you make it immutable? That helps nothing and only serves to make the type harder to use. Structs should _rarely_ be immutable, you should always default to mutable and only make things immutable if there's a good reason for it. If the struct itself is in an immutable position then it inherits the immutability, which handles all of the reasons why you might otherwise default to immutable.<br class=""></div></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap: break-word;" class=""><div class="">Hmm, food for thought… guess I still haven’t completely understood Swift’s handling of immutability… thanks for pointing that out!</div><div class=""></div></div><div style="word-wrap: break-word;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="">2) didSet isn't triggered in init. There's no redundancy.<br class=""></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap: break-word;" class=""><div class="">You are right, of course. I forgot that when I wrote the mail.</div><div class=""></div></div><div style="word-wrap: break-word;" class=""><div class=""><br class=""><blockquote type="cite" class=""><div class=""><div class="">3) You really really want var properties anyway, it's pointless to use let properties.</div></div></blockquote><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><blockquote type="cite" class=""><div class=""><div class="">I think cases like this will be rare so I still think a warning is a good idea. Something like -Wno-overwrite-memberwise-init would allow it to be suppressed in cases where you actually do intend to do this. Would that satisfy you?<br class=""></div></div></blockquote><div class=""> </div><div class="">No. It's not appropriate to have the only way to suppress a warning on perfectly legal code to be passing a flag to the swiftc invocation. Especially because we have no precedent yet for even having flags like that.<br class=""></div><div class=""> </div><div class="">What's wrong with the suggestion to make the warning behave the same way as dead store warnings (e.g. warn if the property is overwritten without any prior reads)? We already have logic for doing this kind of analysis.<br class=""></div></div></blockquote><div class=""> </div><div class=""> </div><div class="">I think this would not be sufficient, because this would not allow overwriting a property based on the value of another property which might be necessary as well.<br class=""></div></div></blockquote><div class=""> </div><div class="">That seems much less likely to be necessary, because if you're doing that, then you're completely ignoring one of your parameters.</div></div></blockquote><blockquote type="cite" class=""><div class=""><div class=""> </div><blockquote type="cite" class=""><div class=""><div class="">Actually isn’t this what happens in your example? The property origin is overwritten without being read, so this would generate the warning, or did I understand something wrong?<br class=""></div></div></blockquote><div class=""> </div><div class="">Origin is being modified. Modification reads it first. `x += 2` reads `x` before writing to it.<br class=""></div></div></blockquote><div class=""><br class=""></div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class="">I stand corrected.</div><div class=""><br class=""></div><div class="">-Thorsten</div></div></div><div style="word-wrap: break-word;" class=""><div class=""><div class=""><br class=""></div><br class=""><blockquote type="cite" class=""><div class=""><div class=""> </div><div class="">-Kevin Ballard</div><div class=""> </div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=1MXK54sosN3xru3iYcLt0oBZ2w20i49gyogXctgrspe4Lg9TcDLfECvApkQ3YKnyH-2FrgKXyeYrvQx3EdWvkgdtW4823SfQYc9PhfhhsxvAmN-2FlmB70W2SL9xIEg7oqoHiNkAhq6cpKeGPEdfbG3chTw0UvyIOWEtlTJuMEvuMN8YGP8zVjOavKkqWyKTE5ULQ4luT5OfPLvKTwdEhzRk7PKrqaBV1C9L7Wzhbo-2Bwgbk-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div></div><div style="word-wrap: break-word;" class=""><div class=""></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=fuWmDRE6-2FDdvdUHeLHruUfdigJaxz7nh99l6HfkulY9LT-2BVr5gfa4RB8tRbJMyRa4FAKJqkXk3zv-2B-2Fn-2BRYRzEJrQnzIYwzA08f2yg10MjmKqAq10WiYvnsQ7sLqm3Wt7pHm1ZMzVJWizDtbVa4UGWfhCAWhzRFFs36ODbI-2FVh13QHNlPgbsMzcj6Wg5OxkwMFGW1nO4oA7wZB-2FIlM5tOp-2BqNzldpQj2DnYP6LJ6wOLE-3D" alt="" width="1" height="1" border="0" style="min-height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""></div>_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a><br class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></blockquote></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=eLFMrKDT8iBxZ-2Fbnk-2BZqvSchNN-2FvYXdceA0T7VxwkAcUPIgw0dqQRqhEdDOzzH6sPdS8Jht-2FF0O4NX8XY452MzOMpBIVVdsCh5lOwKUUR3WTuLeLOXps020uR6pzMZ2q0AyTRVBpeDQAKt4gASilXhhT4CEJygLIRwJQ-2FqPJnj2DZUzRG9y6pMW6l8WNXBVUYABywrMlqeGexSNPfZHo9XoVtsVlfoQniKOKV5cYX44-3D" alt="" width="1" height="1" border="0" 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space"> </span>_______________________________________________</span><br 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=""><span 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>