<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 Dec 16, 2015, at 2:07 PM, Jacob Bandes-Storch via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">I agree it wouldn't/shouldn't be different. But it's worth mentioning in the proposal.</div></div></blockquote><div><br class=""></div>Seems like a distraction to me, FWIW.</div><div><br class=""></div><div><blockquote type="cite" class=""><div class=""><div dir="ltr" class=""><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class="">Jacob Bandes-Storch<br class=""></div></div></div></div>
<br class=""><div class="gmail_quote">On Wed, Dec 16, 2015 at 2:04 PM, Marc Knaup via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class="">The threading issue affects all operators like <font face="monospace, monospace" class="">+=, -=, *=</font> etc. and they are not going to be removed.<div class="">I don't think <font face="monospace, monospace" class="">??=</font> would be any different in this case.</div></div><div class=""><div class="h5"><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Dec 16, 2015 at 10:58 PM, Javier Soto via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr" class=""><div class="">I think it would be worth mentioning in the proposal the threading implications of this operator. The trickyness comes from the fact that suddenly that expression is performing a call to both the getter *and* the setter, so even if those 2 were to be protected via locks, there's still the possibility of race-conditions. Someone else mentioned this is of course also the case with operators such as&nbsp;++ (which I believe Lattner was in favor of stripping from the language)</div><div class=""><br class=""></div><div class="">Not saying that this operator shouldn't exist for this reason, but I do think it's important to realize the complexity it brings to add an operator that does more than is immediately obvious, since that's often times a recipe for any developer making this sort of mistake.</div><div class="">I would lean towards -1, but I do acknowledge that in some circumstances it can simplify some code.</div></div><br class=""><div class="gmail_quote"><div class=""><div class=""><div dir="ltr" class="">On Wed, Dec 16, 2015 at 8:50 AM James Campbell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""></div></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class=""><div class=""><div dir="ltr" class="">I've started a formal proposal here:<div class=""><br class=""></div><div class=""><a href="https://github.com/apple/swift-evolution/pull/63" target="_blank" class="">https://github.com/apple/swift-evolution/pull/63</a><br class=""></div></div><div class="gmail_extra"></div><div class="gmail_extra"><br class=""><div class="gmail_quote">On Wed, Dec 16, 2015 at 4:48 PM, Dave Abrahams via swift-evolution <span dir="ltr" class="">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt;</span> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word" class=""><span class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 16, 2015, at 6:22 AM, Kevin Wooten via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="font-family:AvenirNext-Regular;font-size:14px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class=""><blockquote type="cite" class=""><div class=""><br class="">On Dec 16, 2015, at 4:12 AM, Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><div class=""><blockquote type="cite" class=""><div class="">On 16 Dec 2015, at 00:58, Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>&gt; wrote:</div><br 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;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" class="">I tend towards -1 for multiple reasons:<div class=""><ul class=""><li class="">It has little value for local variables. In most cases you want to use the value you assign to a local variable and assigning it to an optional variable would require a subsequent unwrapping. In most cases where local variables are involved "var x = y ?? z" is satisfying as it creates a non-optional value iff z is non-optional.<br class=""><br class=""></li><li class="">It seems to be a rare use case that you set a value of an optional property which is currently nil and without also using that value directly within the same context. Quickly checking my Swift apps reveals only very little such use cases.<br class=""><br class=""></li><li class="">The remaining cases could expressed like "object.property = object.property ?? …" or using "if object.property == nil { … }".<br class="">While it is true that variable and property name could be very long, this is an unlikely case of an already rare case which decreases the value of the proposed assignment operator even further.<br class=""><br class=""></li><li class="">Most important though is that such an optional assignment operator would work differently from all other assignment operators. The right operand would never be executed if the variable being assigned is already non-nil. This will likely be unexpected for a lot of developers who expect similar behavior like in all other assignments.</li></ul></div></div></div></blockquote>I think these are all very good points. Seems like the only really practical use would be restricted to:</div><div class="">object.property ??= val</div><div class=""><br class=""></div><div class="">Instead of:</div><div class="">object.property = object.property ?? val</div><div class=""><br class=""></div><div class="">Is it worth it for that one scenario? As Marc pointed out, the ?? operator is much more versatile as it can also be used to return a non-optional value.</div></div></div></blockquote><div class=""><br class=""></div><div class="">After perusing our Swift code it turns out that we use the long form (a = a ?? def) quite a bit.&nbsp; As it was previously mentioned it, when the variables is named “a” it’s clearly not an issue, but this is…</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; messagesViewController.chatTitleName = &nbsp;messagesViewController.chatTitleName ?? “Default”</div><div class=""><br class=""></div><div class="">(Those are effectively real world variable names).&nbsp;</div><div class=""><br class=""></div><div class="">I think quite a bit of the clarity of this statement is lost by the duplication and the proposed form..</div><div class=""><br class=""></div><div class="">&nbsp; &nbsp; messagesViewController.chatTitleName ??= “Default”</div><div class=""><br class=""></div><div class="">clears it up fairly well.</div></div></div></blockquote><br class=""></div></span><div class="">A few points:</div><div class=""><br class=""></div><div class="">1. I've always thought we needed something like this; glad to see it discussed</div><div class=""><br class=""></div><div class="">2. This is also applicable to dictionaries:</div><div class=""><br class=""></div><div class="">&nbsp;&nbsp;<span style="font-family:AvenirNext-Regular" class="">messagesViewController.titleNames["chat"] ??= "Default"</span></div><div class=""><span style="font-family:AvenirNext-Regular" class=""><br class=""></span></div><div class=""><div class=""><span style="font-family:AvenirNext-Regular" class="">3. I think it may be time for a formal proposal :-)</span></div><div class=""><span style="font-family:AvenirNext-Regular" class=""><br class=""></span></div><div class=""><span style="font-family:AvenirNext-Regular" class="">4. One way the community can help us to evaluate it would be to create the API in an extension in your own code, actually apply it in your project, and evaluate what it does for readability.</span></div></div><div class=""><br class=""></div><div class="">Thanks,</div><div class=""><br class=""></div><div class="">-Dave</div><div class=""><div class=""><div class=""><br class=""></div><br class="">

</div>
<br class=""></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=xV0JY-2FdZMnUMvSFtZnLiBPRTDDOSQf3-2FpH33HYOlBxE8Dztf2igHB4G3uzzyiEeIq83AyeZQumQgYLrHamdS72mfCKe6-2Bhr77A4r-2BU7KOwmQw9JzwH5BmhAb5ifzhMr2ULdKDnnqtfwrq6G3nEAd0TrjjAJIIWOoXweaU1Rz2ds7HQCAL6-2FsPufaRiTp0wpEyds1QGJI96C1Q8p0cXa0OFmpjsQwHGMOId4XILZwDGc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
</div>
<br class="">_______________________________________________<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="">
<br class=""></blockquote></div><br class=""><br clear="all" class=""><div class=""><br class=""></div></div><div class="gmail_extra">-- <br class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div dir="ltr" class=""><div class=""><span style="font-size:16px;line-height:19.2px" class=""></span><span style="font-size:12.8px" class="">&nbsp;Wizard</span><br class=""></div><div class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a></div><div class=""><a href="tel:%2B44%207523%20279%20698" value="+447523279698" target="_blank" class="">+44 7523 279 698</a></div></div></div></div></div></div>
</div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=EmLgVGNgdilXys3cXWyAWvOFC2-2FejnHkMVv8PyEdfbqO6OGw-2FII9SVJmBSXHkCj6k8UOh42sgPhCJk2naDwzyrKMct6oqA8QJ3GBg20LYtdx1yEpnGhikeqW2RIhCteS6eJm8BWhqgzVpv32-2FbdNbvja9AG-2BGTQPYBFVEKdCeeksSj9iFhjv7pXIOVdhUC146nS2uAcaqb3yRRGJddoeRx0PXjdZsNyw8nQoJXBktAk-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
_______________________________________________<span class=""><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="">
</span></blockquote></div><span class=""><font color="#888888" class=""><div dir="ltr" class="">-- <br class=""></div>Javier Soto
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=6ZGE61OxINd5lLe2xYh9Ku-2BXbixWNr2nvfzp2IB1sZitWlGSp2JCEkW1N6raH2qoZXWv-2BqY82aJGBdvpGhLiWlJYhU5Zvzm24aaQtGA29SHH5NkT2aQuYgSNTvOIDjfR1CdYMWEhQ2owTRpWaahFRT7p7jNWyv7tlkie8yGGdjI7P0tHafQ7gnimSF095qPlHTnYBCJtGak2vv6xryxcZNe9l-2FVWa2V5p91oO3QW3Ac-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
</font></span><br class="">_______________________________________________<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="">
<br class=""></blockquote></div><br class=""></div>
</div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qxgjh6EsuJE0ARUaKepGRBH9PPnIthGCLRN8BHFUGJA57pN366wpwOk5llfqnbbVnVvVdxnNUtRWsO9v11YsB6djyWryTGOqf8vLJEG6v2Nr0GfYjhSBDLCViVxeRwf6vfu-2B-2B0b1fmH2fbPcSXflWgvMx-2FWhJfcKHBuwXc5vpcLRAXlbV06De3j-2FW6htfPXGrw-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important" class="">
<br class="">_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="mailto:swift-evolution@swift.org" 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="">
<br class=""></blockquote></div><br class=""></div></div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=JfMPa-2F7wwZPzsZ3QKA8NjtONIYX4SjbWuUxtpfsTY2jTIFF1V5oR3xpR8tEqGkAMGqCobKEposrkwJbmRUrxfsdKP5PLlTt96hrYnfR4oTpF9F6cKA1W-2BxXR-2B7BfgGFgJFaIeW5L7-2BbXfOTcBqdX-2BY1s9XhatNuvh44dX7ZB6fBwLr3-2BMde6ppe44VCunAFnl4G7k-2Bp-2BCDP67gtpphb4OLebn9ZQsBn-2FG5iMZIVlMdQ-3D" alt="" width="1" height="1" border="0" style="height:1px !important;width:1px !important;border-width:0 !important;margin-top:0 !important;margin-bottom:0 !important;margin-right:0 !important;margin-left:0 !important;padding-top:0 !important;padding-bottom:0 !important;padding-right:0 !important;padding-left:0 !important;" class="">
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""><div class="">
-Dave<div class=""><br class=""></div><br class="Apple-interchange-newline">

</div>
<br class=""></body></html>