<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="">Ruby recently ran into a similar problem from the other direction - they wanted to support ?. syntax, but ‘?’ was already legal in identifier names (and used) to represent result values which are meant to be considered ‘truthy’. In the end, they went with a different “&." syntax because<div class="">1. This meant ‘?’ was both a naming convention and an operation</div><div class=""></div><div class="">2. Too many question marks made the code psychologically confusing</div><div class="">3. They already had to change the syntax (to ‘.?’) to make code unambiguous</div><div class=""><br class=""></div><div class=""><div class="">An naming system or pattern indicating something optional isn’t a bad idea - but it probably shouldn’t use ‘?’ for the same reason. A ‘?’ is already used heavily to indicate actions against optionals, and every time you see that identifier you will have to think about whether you are just referencing it by name, or performing some operation on it.</div><div class=""><br class=""></div><div class="">I think you however are pushing for a mandatory naming system for optionals - to make it clear in your examples below that ‘x’ needs to be treated as an optional, not as the type contained within. This makes coming up with an acceptable system significantly harder.</div><div class=""><br class=""></div><div class="">-DW</div><div class=""><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 8:44 AM, Amir Michail <<a href="mailto:a.michail@me.com" class="">a.michail@me.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><div style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><div class="">I don’t want to remember if a variable is optional. I want to see it in the variable name.</div><div class=""><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: 0px 0px 0px 0.8ex; border-left-width: 1px; border-left-color: rgb(204, 204, 204); border-left-style: 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 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="" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;"></div></blockquote></div><br class=""></div></div></body></html>