<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=""><div class="">I disagree. I think those are exactly the wrong use cases for ??= and, in fact, could be used as an argument against this proposal (??= encouraging unidiomatic behavior).</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">let object = try? UnsupportedMessage(text: "James", type:.Text, date:NSDate()) ?? FailedObject()</div><div class=""><br class=""></div><div class="">vs</div><div class=""><br class=""></div><div class="">var object = try? Message(text: "James", type:.Text, date:NSDate())</div><div class="">object ??= UnsupportedMessage()</div></div></blockquote><br class=""></div><div class="">The first example — though an admittedly long line — is clearly better to my eyes.</div><div class=""><br class=""></div><div class="">The second one does *two* things considered undesirable in Swift:</div><div class=""><br class=""></div><div class="">- it creates a mutable variable even though it’s not necessary</div><div class="">- it leaves `object` as an Optional, even though we don’t mean it to actually ever be nil.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div dir="ltr" class=""><div class="">This could also be great for the null object pattern where you may not want a variable to be nil, you may want some sort of null object that is vended in cases of failure that could log this error.</div></div></blockquote><br class=""></div><div class="">I agree with the premise — a null object or value is often much better than a nil (e.g. [] vs nil when there isn’t a semantic diff between the two). But when you use ??=, the variable you’re mutating is still an Optional and could be nil!</div><div class=""><br class=""></div><div class="">* * *</div><div class=""><br class=""></div><div class="">I see two reasons to use ??=:</div><div class=""><br class=""></div><div class="">- when applying a default value to a dictionary (or a dictionary-like structure), since subscripting it will produce Optionals *either way*</div><div class="">- when mutating a property (not a local variable!), that is (has to be) optional and mutable *either way*</div><div class=""><br class=""></div><div class="">It’s a useful shortcut in those two circumstances. But it is not desirable to damage our Swift code with needless optionals or mutability so we can use ??=.</div><div class=""><br class=""></div>best,<br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div><blockquote type="cite" class=""><div class="">On 13 Feb 2016, at 13:10, James Campbell <<a href="mailto:james@supmenow.com" class="">james@supmenow.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div dir="ltr" class="">One common case could be for a error catching, consider this:<div class=""><br class=""></div><div class="">let object = try? UnsupportedMessage(text: "James", type:.Text, date:NSDate()) ?? FailedObject()</div><div class=""><br class=""></div><div class="">vs</div><div class=""><br class=""></div><div class="">var object = try? Message(text: "James", type:.Text, date:NSDate())</div><div class="">object ??= UnsupportedMessage()<br class=""></div><div class=""><br class=""></div><div class="">Why would we need this? I have a chat application where if it gets a message it doesn't understand it will throw an error. In the past I would handle this errors by returning nil like so. However we want to communicate to the user that they missing content by vending a UnsupportedMessage object which shows the UI to prompt them to upgrade.</div><div class=""><br class=""></div><div class="">If the object being constructed has a lot of variables then it could be lost off the side of the screen. I feel ??= is more concise in this case.</div><div class=""><br class=""></div><div class="">This could also be great for the null object pattern where you may not want a variable to be nil, you may want some sort of null object that is vended in cases of failure that could log this error.</div></div><div class="gmail_extra"><br clear="all" class=""><div class=""><div class="gmail_signature"><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><div class=""><div dir="ltr" class=""><p class=""><b class=""><font color="#cc0000" class="">___________________________________</font></b></p><p class=""><b class="">James⎥Head of Awesome</b></p><p class=""><b class=""><font color="#cc0000" class=""><a href="mailto:james@supmenow.com" target="_blank" class="">james@supmenow.com</a>⎥<a href="http://supmenow.com/" target="_blank" class="">supmenow.com</a></font></b></p><p class=""><b class=""><font size="2" class="">Sup</font></b></p><p class=""><b class=""><font size="2" class="">Runway East
</font></b></p><p class=""><b class=""><font size="2" class="">10 Finsbury Square</font></b></p><p class=""><b class=""><font size="2" class="">London</font></b></p><p class=""><b class=""><font size="2" class="">
EC2A 1AF </font></b></p></div></div></div></div></div></div></div>
<br class=""><div class="gmail_quote">On Sat, Feb 13, 2016 at 11:20 AM, Taras Zakharko via swift-evolution <span dir="ltr" class=""><<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>></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="">I think the proposal should include some discussion on the common cases where this operator would be useful. As such, I don’t see much hard of including this, except that I am not sure that the problem is significant enough to warrant a reaction. <div class=""><br class=""></div><div class="">— T</div><div class=""><div class="h5"><div class=""><br class=""></div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 13 Feb 2016, at 11:11, Radosław Pietruszewski via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class="">+0.5<div class=""><br class=""></div><div class="">I am generally for this proposal, because I don’t see why not — there are cases where this is useful, and it’s symmetric with other X/X= operator pairs, so it’s not like it’s a completely new thing.</div><div class=""><br class=""></div><div class="">However, I don’t think the operator is _as_ useful in Swift as it is in other languages.</div><div class=""><br class=""></div><div class="">In Ruby, for example, it’s extremely common to use `||=` (an equivalent of ??=, more or less) to modify function arguments, e.g. assign default values if nil was passed. But you can’t do that in Swift since SE-0003 removed the ability to mark a parameter as `var`.</div><div class=""><br class=""></div><div class="">So you can’t do that</div><div class=""><br class=""></div><div class=""><span style="white-space:pre-wrap" class="">        </span>arg ??= default</div><div class=""><br class=""></div><div class="">and you have to do</div><div class=""><br class=""></div><div class=""><span style="white-space:pre-wrap" class="">        </span>let arg = arg ?? default</div><div class=""><br class=""></div><div class="">Except you wouldn’t want the earlier version anyway, because `arg` would continue to be an optional. A notion not relevant in a dynamically typed language, but in Swift, it matters.</div><div class=""><br class=""></div><div class="">And I see other cases like this. A proposal to add `??=` to Swift was one of the first Swift radars I filed, because it was just something I was really used to. But with time I realized there are actually relatively few cases where this is useful. And that’s all because of Swift’s characteristics: it’s statically typed, it pushes you to use constants and not variables where possible, optionality is explicit, and avoided when not necessary.</div><div class=""><br class=""></div><div class="">Still, I searched through my code and found _a few_ instances of `??=` (my own implementation), almost all used for dealing with dictionaries (and a dictionary-like structure in a library called SwiftyUserDefaults) — and having this operator definitely improved the clarity of those places.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div style="word-wrap:break-word" class=""><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">What is your evaluation of the proposal?</li></ul></div></blockquote></div><div class="">All in all, I’m for.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div style="word-wrap:break-word" class=""><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">Is the problem being addressed significant enough to warrant a change to Swift?</li></ul></div></blockquote></div><div class="">I’d say yes, because it’s simple to implement, and carries little risk AFAICT. Still, it’s not as significant an improvement as many of the other proposals.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div style="word-wrap:break-word" class=""><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">Does this proposal fit well with the feel and direction of Swift?</li></ul></div></blockquote></div><div class="">Again, ??= is only useful in _some_ cases, and in many other cases you want to avoid optionality and mutability. So it’s not necessarily something we want to encourage a lot, but I don’t see real risk in people trying to damage their Swift code just so they can use ??=. And OTOH having nice tools for dealing with optionality when it’s necessary is a very Swifty thing to do, so overall, yes.</div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div style="word-wrap:break-word" class=""><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li></ul></div></blockquote><div class="">Mostly dynamically typed languages with ||=, Ruby in particular. Also my own implementation of ??= in my projects and <a href="https://github.com/radex/swiftyuserdefaults" target="_blank" class="">https://github.com/radex/swiftyuserdefaults</a></div><br class=""><blockquote type="cite" class=""><div style="word-wrap:break-word" class=""><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul></div></blockquote><div class="">A quick reading of the proposal.</div></div><div class=""><br class=""></div><div class="">Best,<br class=""><div class="">
<div class="">— Radek</div>
</div>
<br class=""><div class=""><blockquote type="cite" class=""><div class="">On 13 Feb 2016, at 06:15, Douglas Gregor via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank" class="">swift-evolution@swift.org</a>> wrote:</div><br class=""><div class=""><div style="word-wrap:break-word" class=""><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Hello Swift community,</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The review of SE-0024 "Optional Value Setter `??=`" begins now and runs through February 18, 2016. The proposal is available here:</p><blockquote style="margin:0px 0px 16px;padding:0px 15px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);background-color:rgb(255,255,255)" class=""><div style="margin-top:0px;margin-bottom:0px" class=""><font color="#777777" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="3" class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md</a></font></div></blockquote><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Reviews are an important part of the Swift evolution process. All reviews should be sent to the swift-evolution mailing list at</p><blockquote style="margin:0px 0px 16px;padding:0px 15px;color:rgb(119,119,119);border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><div style="margin-top:0px;margin-bottom:0px" class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">or, if you would like to keep your feedback private, directly to the review manager. When replying, please try to keep the proposal link at the top of the message:</p><blockquote style="margin:0px 0px 16px;padding:0px 15px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);background-color:rgb(255,255,255)" class=""><p style="color:rgb(119,119,119);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;margin-top:0px;margin-bottom:16px" class="">Proposal link:</p><blockquote style="margin:0px 0px 16px;padding:0px 15px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221)" class=""><div style="margin-top:0px;margin-bottom:0px" class=""><font color="#777777" face="Helvetica Neue, Helvetica, Segoe UI, Arial, freesans, sans-serif, Apple Color Emoji, Segoe UI Emoji, Segoe UI Symbol" size="3" class=""><a href="https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/proposals/0024-optional-value-setter.md</a></font></div></blockquote><p style="color:rgb(119,119,119);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;margin-top:0px;margin-bottom:16px" class="">Reply text</p><blockquote style="color:rgb(119,119,119);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;margin:0px;padding:0px 15px;border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221)" class=""><div style="margin-top:0px;margin-bottom:0px" class="">Other replies</div></blockquote></blockquote><h5 style="margin-top:1em;margin-bottom:16px;line-height:1.4;font-size:1em;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';background-color:rgb(255,255,255)" class=""><a href="https://github.com/apple/swift-evolution#what-goes-into-a-review-1" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none;display:inline-block;padding-right:2px;line-height:1.1" target="_blank" class=""><u class=""></u><u class=""></u><u class=""></u><u class=""></u></a>What goes into a review?</h5><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">The goal of the review process is to improve the proposal under review through constructive criticism and, eventually, determine the direction of Swift. When writing your review, here are some questions you might want to answer in your review:</p><ul style="padding:0px 0px 0px 2em;margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><li class="">What is your evaluation of the proposal?</li><li class="">Is the problem being addressed significant enough to warrant a change to Swift?</li><li class="">Does this proposal fit well with the feel and direction of Swift?</li><li class="">If you have used other languages or libraries with a similar feature, how do you feel that this proposal compares to those?</li><li class="">How much effort did you put into your review? A glance, a quick reading, or an in-depth study?</li></ul><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">More information about the Swift evolution process is available at</p><blockquote style="margin:0px 0px 16px;padding:0px 15px;color:rgb(119,119,119);border-left-width:4px;border-left-style:solid;border-left-color:rgb(221,221,221);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class=""><div style="margin-top:0px;margin-bottom:0px" class=""><a href="https://github.com/apple/swift-evolution/blob/master/process.md" style="background-color:transparent;color:rgb(64,120,192);text-decoration:none" target="_blank" class="">https://github.com/apple/swift-evolution/blob/master/process.md</a></div></blockquote><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Thank you,</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Doug Gregor</p><p style="margin-top:0px;margin-bottom:16px;color:rgb(51,51,51);font-family:'Helvetica Neue',Helvetica,'Segoe UI',Arial,freesans,sans-serif,'Apple Color Emoji','Segoe UI Emoji','Segoe UI Symbol';font-size:16px;background-color:rgb(255,255,255)" class="">Review Manager</p></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=""></div></blockquote></div><br class=""></div></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=""></div></blockquote></div><br class=""></div></div></div></div><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></blockquote></div><br class=""></body></html>