<html><head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head><body dir="auto"><div></div><div><br></div><div><br>Am 31.05.2016 um 23:01 schrieb Haravikk via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a>&gt;:<br><br></div><blockquote type="cite"><div><meta http-equiv="Content-Type" content="text/html charset=utf-8"><br class=""><div><blockquote type="cite" class=""><div class="">On 31 May 2016, at 18:57, Erica Sadun via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; wrote:</div><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class=""><br class=""></div><div class="">* Should `where` clauses be allowed where the contents of the where clause have no connection to the condition that precedes it?</div></div></div></div></blockquote><blockquote type="cite" class=""><div class=""><div style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><div class=""><div class="">* Is there a technical way to to check for such conformance?</div><div class="">* Should the `where` clause be left unconstrained, as it currently is in switch statements and for loops, etc, which is consistent with the rest of the language but contrary to the spirit of safety in Swift?</div><div class="">* Should `where` clauses be re-evaluated throughout the language?</div></div></div></div></blockquote><br class=""></div><div>Personally I’m not sure that where should need to be constrained, in fact one of the examples given as “incorrect” is arguably not so:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let foo = x where y &lt; z { … }</font></div><div><br class=""></div><div>In this case y &lt; z doesn’t appear strictly related to the optional binding, but it may still be a condition of it, in essence it’s saying “bind foo if this is true”. </div></div></blockquote><div><br></div><div>This is a very good point!! I totally agree with that!</div><div><br></div><div>-Thorsten&nbsp;</div><div><br></div><div><br></div><br><blockquote type="cite"><div><div>This is interesting because the compiler is actually free to evaluate y &lt; z first, and only perform the binding afterwards. Actually this is also true in the following case:</div><div><br class=""></div><div><font face="Monaco" class=""><span class="Apple-tab-span" style="white-space:pre">        </span>if let foo = x where foo &gt; 5 { … }</font></div><div><br class=""></div><div>To evaluate foo &gt; 5 the compiler doesn’t actually need to unwrap x, it just needs to know if x is .Some, in which case it can compare the value and only if the comparison succeeds actually copy it into a variable and continue.</div><div><br class=""></div><div>Of course statements separated by semi-colons can be reordered behind the scenes if the compiler wants to do-so, so long as the logic doesn’t change, but I find that where reads better with that implication in mind. It reads visually like “bind this if this test is true” rather than “bind this, then test this”.</div><div><br class=""></div><div>Plus it just looks nicer (to me); sometimes aesthetics are important, and the majority of cases don’t need the complexity of lots of conditionals that need separating, sometimes a pattern and a condition, or a binding and a condition is enough, and the where clause has this covered, and keeps these forms of conditional visually distinct. Much more complex cases will benefit from semi-colons, which in turn will make them visually distinct too, even if a lot of the building blocks are the same.</div><div><br class=""></div><div>Put another way, I tend to think of pattern matching, conditional binding and regular logic as three completely different forms of conditional (I suppose they are in fact at present), the separators as proposed will let you mix and match these cleanly, which has the potential for some overlap sure, but I think developers can be left to resolve that for themselves by choosing whether to group a conditional with where, or separate it.</div><div><br class=""></div><div><br class=""></div><div>Anyway, it doesn’t really matter overall, as the addition of semi-colons/new-lines as separators isn’t dependent upon the removal of where clauses, so they can be removed later if it’s deemed useful. In fact, doing it this way would be a better way to do it as it gives us a period in which both features will be available, and we can just wait and see what people actually use. If where clauses are ignored in favour of semi-colons/new-lines, then at this point it will be trivial to replace them, as you can non-destructively remove the feature by simply swapping the where keyword from these types of conditionals for a semi-colon, or provide a fixit to do this, as functionally they will be identical.</div></div></blockquote><blockquote type="cite"><div><span>_______________________________________________</span><br><span>swift-evolution mailing list</span><br><span><a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a></span><br><span><a href="https://lists.swift.org/mailman/listinfo/swift-evolution">https://lists.swift.org/mailman/listinfo/swift-evolution</a></span><br></div></blockquote></body></html>