<div dir="ltr">During the review of the proposal for a '??=' operator, one of the given disadvantages was the confusion over the meaning of '??'. Since one of its two meanings is that it nil-coalesces a chained expression into a non-optional result, it might be misinterpreted that given the expression 'lhs ??= rhs' and a non-optional 'rhs', 'lhs' would no longer be optional. '??' is an overloaded operator; unloading one of its two responsibilities to a second operator would improve code clarity.<div><br></div><div>Radoslaw's example is simplistic because '[]' is unambiguously non-optional. So let's replace it:</div><div><br></div><div><span style="font-size:13px">var value = someArray ?? someFallback ?? secondaryFallback ?? tertiaryFallback</span><br></div><div><br></div><div>Is 'value' optional or non-optional?</div><div><br></div><div><span style="font-size:13px">var value = someArray ?? someFallback ?? secondaryFallback ?! tertiaryFallback</span><br></div><div><br></div><div>Now we can see immediately that 'value' is optional in the first case, and non-optional in the second. However, since '!' is associated with assertions, I agree that perhaps there's a better choice of operator for this meaning.</div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Mar 7, 2016 at 10:26 PM, Radosław Pietruszewski <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div style="word-wrap:break-word"><div>-1, never seen a real world situation where this would be confusing/problematic.</div><div><br></div><div>Having one operator is nice for chaining:</div><div><br></div><div>var value = someArray ?? someFallback ?? secondaryFallback ?? []</div><br><div>
<div>— Radek</div>
</div>
<br><div><blockquote type="cite"><div><div class="h5"><div>On 07 Mar 2016, at 22:29, Sébastien Blondiau via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br></div></div><div><div><div class="h5"><div style="word-wrap:break-word"><div>Currently, there is only one nil coalescing operator, which may return an optional value or not, depending on the second parameter. This variability can leads to unclear line of code:</div><div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo"><div style="margin:0px"><span style="color:rgb(187,44,162)">var</span><span> isItOptionalOrNot = </span><font color="#4f8187">value</font><span> ?? </span><font color="#4f8187">otherValue</font></div><div style="color:rgb(79,129,135);margin:0px"><br></div></div><div>I think there should be two distinct operators:</div><div><br></div><div><div style="margin:0px;font-size:11px;font-family:Menlo"><div style="font-family:Helvetica;font-size:12px"><div style="margin:0px;font-size:11px;font-family:Menlo"><span style="color:rgb(187,44,162)">var</span><span> certainlyOptional = </span><font color="#4f8187">value</font><span> </span><span>?? </span><font color="#4f8187">otherValue</font></div><div><div style="margin:0px;font-size:11px;font-family:Menlo;color:rgb(79,129,135)"><span style="color:rgb(187,44,162)">var</span><span> </span><span>certainlyNotOptional</span><span> = </span><font color="#4f8187">value</font><span> ?! </span><font color="#4f8187">notOptionalValue</font></div></div><div><br></div></div></div></div><div>In my point of view, this differentiation brings more clarity about wether the result is an optional or not.</div></div><div><br></div><div>What's your opinion?</div><div><br></div><div>--</div><div>Sébastien Blondiau</div></div></div></div><span class="">_______________________________________________<br>swift-evolution mailing list<br><a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a><br><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br></span></div></blockquote></div><br></div><br>_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br></blockquote></div><br></div>