<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 4, 2015, at 10:41 AM, J. Cheyo Jimenez <<a href="mailto:cheyo@masters3d.com" class="">cheyo@masters3d.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class="">This a little confusing, I don't think adding yet another question mark helps. <span class=""></span>The ?? (<font size="2" class=""><span style="background-color:rgba(255,255,255,0)" class=""> nil coalescing operator</span></font>) already included in swift handles checking for nil values. If anything, the ternary operator just makes matters worse in this example. If else would be better imo. <div class=""><br class=""><div class=""><a href="https://lists.swift.org/pipermail/swift-evolution/2015-December/000133.html" class="">https://lists.swift.org/pipermail/swift-evolution/2015-December/000133.html</a><br class=""></div><div class=""><br class=""><br class=""></div></div></div></blockquote><div><br class=""></div><div>I don’t want to remember if a variable is optional. I want to see it in the variable name.</div><div><br class=""></div><blockquote type="cite" class=""><div class=""><div class=""><div class="">On Friday, December 4, 2015, Amir Michail <<a href="mailto:a.michail@me.com" class="">a.michail@me.com</a>> wrote:<br class=""><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">So for example the following (probable) bug would result in a compile error:<br class="">
<br class="">
let f = x < 5 // where x is optional and could be nil<br class="">
<br class="">
If that was really what was intended, you would need to write:<br class="">
<br class="">
let f = x? < 5<br class="">
<br class="">
Similarly, the rule would also apply for functions that return an optional type:<br class="">
<br class="">
let f = x()? < 5<br class="">
<br class="">
A major advantage of this approach is it would encourage programmers to unwrap optionals early to avoid writing “?” and “?!" frequently in their code.<br class="">
<br class="">
Note that conditional chaining would just make use of the existing “?” suffix. There is no need to add another “?” after that.<br class="">
<br class="">
let f = x?.g?.h<br class="">
let f = x()?.g?.h<br class="">
<br class="">
As for implicitly unwrapped optionals, a “?” suffix would only be used when you want to treat a value as an optional (e.g., when comparing it to nil). For example, for x of type Int?, one could write:<br class="">
<br class="">
let y = (x? == nil) ? 0 : x<br class="">
<br class="">
_______________________________________________<br class="">
swift-evolution mailing list<br class="">
<a href="javascript:;" onclick="_e(event, 'cvml', 'swift-evolution@swift.org')" 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></blockquote></div><br class=""></body></html>