<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="">Pyry,</div><div class=""><br class=""><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class="">Let me put it differently: I still haven't seen, nor was I able to conceive myself, a&nbsp;<i class="">realistic</i>&nbsp;example where `<span class="" style="font-family: Menlo;">??</span>` would cause problems.</div></div></div></blockquote></div><div class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class=""><div class=""><br class=""></div></div></div></div><div class="">An example of broken code from real project:</div><div class=""><br class=""></div><div class=""><div>let allParameters: [String: Any?] =<br class="">&nbsp;defaultParameters["sendMessage"] ?? [:] +<br class="">&nbsp;parameters +<br class="">&nbsp;["chat_id": chat_id, "text": text]</div><div><br class=""></div><div>I think that the precedence of ?? is counter-intuitive because it's mainly used as</div><div>nil-unwrapping operator and there are often multiple optionals in an expression.</div><div>It's too easy to make errors like this one:</div><div><br class=""></div><div>let value = x ?? defaultX + y ?? defaultY</div><div>let value = x ?? (defaultX + y ?? defaultY)</div><div><br class=""></div><div>Imho braces should be required in these expressions.</div><div><br class=""></div><div>Even this expression is confusing and in my opinion would only benefit from</div><div>braces:</div><div>let value = x ?? defaultX + modifier</div><div><br class=""></div><div>Also, low precedence of ?? is a source of confusion in other languages, for example:</div><div><a href="http://www.codeproject.com/Tips/721145/Beware-The-null-coalescing-operator-is-low-in-the" class="">http://www.codeproject.com/Tips/721145/Beware-The-null-coalescing-operator-is-low-in-the</a></div></div><div class="">but in C# this operator isn't used as often as in Swift, so it's not a major issue there.</div><div class=""><br class=""></div><div class="">Andrey</div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On 08 Sep 2016, at 15:20, Pyry Jahkola 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=""><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=""><div class=""><div class="">Vladimir,</div><div class=""><br class=""></div><div class="">I don't disagree with you about bitwise operations (please read my email again). I'm saying when it comes to `<span style="font-family: Menlo;" class="">??</span>`, we don't have the evidence necessary for proposing a breaking change.</div><div class=""><br class=""></div></div><div class=""><blockquote type="cite" class=""><div class="">On 08 Sep 2016, at 14:21, Vladimir.S &lt;<a href="mailto:svabox@gmail.com" class="">svabox@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="">Why do you need to see some precedence (…) while this construction is so simple and obviously would be used often and *will* cause bugs. (…)<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Let me put it differently: I still haven't seen, nor was I able to conceive myself, a <i class="">realistic</i> example where `<span style="font-family: Menlo;" class="">??</span>` would cause problems.</div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><blockquote type="cite" class="">The original motivation by Erica simply failed to compile (…)<br class=""></blockquote><br class="">Sorry, but you are just not right.</div></div></blockquote><div class=""><br class=""></div><div class="">Let me remind you that the original motivation from Erica wasn't about which way `<font face="Menlo" class="">foundIndex ?? lastIndex + 1</font>` goes but about whether `<font face="Menlo" class=""><b class="">let</b> y = 5 + x ?? 2</font>` compiles at all.</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">The code compiles without even warning:<br class=""><br class="">let foundIndex : Int? = 1<br class="">let lastIndex = 2<br class=""><br class="">let nextIndex = foundIndex ?? lastIndex + 1<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">It certainly does compile. <b class="">But is it realistic?</b> Look at the variable names: does this code make any sense at all? What is `<font face="Menlo" class="">lastIndex</font>`? What is `<font face="Menlo" class="">lastIndex + 1</font>`? Why not `<font face="Menlo" class="">things.endIndex</font>`? Indeed, why not:</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; <b class="">let</b> foundIndex: Int? = things.index(of: something)</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; <b class="">let</b> nextIndex = foundIndex.map { $0 + 1 } ?? things.endIndex</font></div><div class=""><br class=""></div><div class="">That said, I give you the benefit of the doubt – I still believe there <i class="">can</i> be examples where `<font face="Menlo" class="">??</font>` may be confusing. But without seeing any such examples from the real world, I don't think we have a case for changing `<span style="font-family: Menlo;" class="">??</span>`.</div><div class=""><br class=""></div><blockquote type="cite" class=""><div class=""><div class="">After I showed the code compiles, would you change your opinion?<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">No, not with these examples.</div><div class=""><br class=""></div><div class="">* * *</div><div class=""><br class=""></div><div class="">Finally:</div><br class=""><blockquote type="cite" class=""><div class=""><div class="">IMO the best solution (…) would be to require (…) parenthesis when operators from different groups are mixed in the same expression. IMO no need in complex rules to make Swift safer. I.e. when you have a = 10 + 5 * 10 - you don't need parenthesis, when you have a = b &lt;&lt; 4 &nbsp;- also all is ok, but if you have a = b &lt;&lt; 4 + 5 * 10 - you'll have a warning until add parenthesis to make your intention clear. (…)<br class=""></div></div></blockquote><div class=""><br class=""></div><div class="">Look, changing how `<font face="Menlo" class="">b &lt;&lt; 4 + 5 * 10</font>` is compiled is <b class="">exactly</b> what I was proposing. With my changes, it would become a compiler error. IMO, it ought to be parenthesised explicitly as either</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; (b &lt;&lt; 4) + 5 * 10</font></div><div class=""><br class=""></div><div class="">or</div><div class=""><br class=""></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; b &lt;&lt; (4 + 5 * 10)</font></div><div class=""><br class=""></div><div class="">depending on which one was intended.</div><div class=""><br class=""></div><div class="">— Pyry</div><div class=""><br class=""></div></div></div>_______________________________________________<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=""></body></html>