<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=""><blockquote type="cite" class=""><div class="" style="font-family: HelveticaNeue;">`<span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;">for object in? array` … suggests that there’s something optional about checking for inclusion, not about the array itself. It could easily be interpreted as “iterate for all non-nil elements of array (where array: [T?])” —&nbsp;a use case arguably more common than this.</span></span></div></blockquote></div><div class=""><div class="" style="font-family: HelveticaNeue;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;"><br class=""></span></span></div></div><div class="" style="font-family: HelveticaNeue;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;">That’s a really good point.</span></span></div><div class="" style="font-family: HelveticaNeue;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;"><br class=""></span></span></div><div class="" style="font-family: HelveticaNeue;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;">P</span></span></div><div class=""><br class=""></div><br class=""><div><blockquote type="cite" class=""><div class="">On Dec 18, 2015, at 3:06 PM, Radosław Pietruszewski &lt;<a href="mailto:radexpl@gmail.com" class="">radexpl@gmail.com</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;">Personally, I’m -1 for the proposal. I see this as a solution to a very minor, fairly rare, and not generalizable problem.</div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;"><br class=""></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;">Perhaps more importantly: the syntax is confusing to my eyes. `<span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;">for object in? array` doesn’t immediately convey its semantics to me. It suggests that there’s something optional about checking for inclusion, not about the array itself. It could easily be interpreted as “iterate for all non-nil elements of array (where array: [T?])” —&nbsp;a use case arguably more common than this.</span></span></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;"><br class=""></span></span></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;">In the vast majority of cases, arrays shouldn’t be optional in the first place. It’s rare that there’s a semantic difference between “empty array” and “no array”.</span></span></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;"><span class="" style="background-color: rgb(255, 255, 255);"><span class="" style="white-space: pre-wrap;"><br class=""></span></span></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;"><blockquote type="cite" class=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><div class="">Sure, in that example it’s quite simple. It’s not the “?? []” syntax itself, which is perfectly clear; it’s having that dangling off the end of some longer expression. In real-world context, it does become additional noise.</div></div></blockquote><br class=""></div><div class="" style="font-family: HelveticaNeue; font-size: 13px; 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;">That is a good point, albeit one that’s more broad than that — I dislike how `as?` often forces me to add additional parentheses — and not strong enough to warrant an introduction of a new `in?` construct IMHO.</div><br class="" style="font-family: HelveticaNeue; font-size: 13px; 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 class="" style="font-family: HelveticaNeue; font-size: 13px; 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 class="">— Radek</div></div><br class="" style="font-family: HelveticaNeue; font-size: 13px; 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 style="font-family: HelveticaNeue; font-size: 13px; 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=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 21:56, Paul Cantrell 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=""><div class="" style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;"><br class=""><blockquote type="cite" class="">On Dec 17, 2015, at 4:08 AM, Jeremy Pereira &lt;<a href="mailto:jeremy.j.pereira@googlemail.com" class="">jeremy.j.pereira@googlemail.com</a>&gt; wrote:<br class=""><br class=""><br class=""><blockquote type="cite" class="">On 16 Dec 2015, at 19:52, Paul Cantrell via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:<br class=""><br class="">I do this a lot:<br class=""><br class="">&nbsp; &nbsp;for object in array ?? [] {<br class=""><br class="">…and it does impair readability a bit at times.<br class=""></blockquote><br class="">Does it? It seems fairly understandable to me even though I have never seen it before.<br class=""></blockquote><div class=""><br class=""></div><div class="">Sure, in that example it’s quite simple. It’s not the “?? []” syntax itself, which is perfectly clear; it’s having that dangling off the end of some longer expression. In real-world context, it does become additional noise.</div><div class=""><br class=""></div><blockquote type="cite" class="">I think there is a good reason for keeping this construct a bit “clunky”. Generally APIs give you a nil array for one of two reasons:<br class=""><br class="">- there was some sort of error in retrieving the elements<br class="">- there were no qualifying elements found.<br class=""></blockquote><div class=""><br class=""></div><div class="">You’re forgetting the third case, the most common one: things not populated / initialized yet. In that case, we often just want to leave a UI blank, for example, and doing nothing is the right behavior.</div><div class=""><br class=""></div><div class="">Doing nothing is the right behavior in a<span class="Apple-converted-space">&nbsp;</span><i class="">lot</i>&nbsp;of cases, and since Swift provides optional sugar for “do nothing if nil” in other cases:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 10.5px;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><font color="#323e7d" class="">foo?.bar = baz</font></span></div></div><div class=""><div class=""><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 10.5px;">&nbsp; &nbsp;&nbsp;<font color="#323e7d" class="">if let foo = bar { }</font></span></div></div></div><div class=""><span class="" style="font-size: 10.5px;"><font color="#323e7d" class=""><br class=""></font></span></div><div class="">…it makes sense to provide it in for loops too.</div><div class=""><br class=""></div><div class="">True, “do nothing” is not the right behavior in all cases. Thus the `for…in` / `for … in?` distinction.</div><div class=""><br class=""></div><blockquote type="cite" class="">In the&nbsp;second case, the API is wrong.</blockquote><br class=""><div class="">Then a lot of APIs are wrong! NSURLComponents, for example:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;"><span class="" style="font-size: 10.5px;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="font-size: 10.5px; color: rgb(50, 62, 125);">for</span><span class="" style="font-size: 10.5px;"><span class="Apple-converted-space">&nbsp;</span>item<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="font-size: 10.5px; color: rgb(50, 62, 125);">in</span><span class="" style="font-size: 10.5px;">&nbsp;urlComponents.</span><span class="" style="font-size: 10.5px; color: rgb(88, 126, 168);">queryItems</span><span class="" style="font-size: 10.5px;">&nbsp;?? []</span></div><div class="" style="margin: 0px; font-size: 10.5px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; { queryDict[item.<span class="" style="color: rgb(88, 126, 168);">name</span>] = item.<span class="" style="color: rgb(88, 126, 168);">value</span><span class="Apple-converted-space">&nbsp;</span>}</div></div><div class=""><br class=""></div><div class="">But then I don’t think NSURLComponents is making a mistake: it distinguishes “no query string” from “empty query string”, but for the purposes of the loop here, there upshot in both cases is “no query items.”</div><div class=""><br class=""></div><div class="">True, ?? [] is minor noise — but given the clarity and low impact on existing code of a `for … in?` counterpart to `for … in`, it’s worth at least considering that option.</div><div class=""><br class=""></div><div class="">Cheers,</div><div class=""><br class=""></div><div class="">Paul</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=4hhvaxvZNsLrnZM9llg93kxoqfFYC8lhv8HAehOIDqKQXtEz44wzr57ueVaQ0SQlINAEWx-2FlQ6heG1BfClLuVCgQj6mVussRh0Fn12l9TvpgflEDodqORozjg-2BCZAnc76mhJLZ09jUOlHA6bL6DTPSKcp3oj78Exc-2Bj9UnzYb2mTXCGZyGarqO57AZOEfF49Q8wEqK1MqLFTqbYTqUPv5Fs1SbdgGmIgpMuyMXoEctE-3D" alt="" width="1" height="1" border="0" class="" style="height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;"></div>_______________________________________________<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" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div></div></blockquote></div><br class=""></body></html>