<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=Windows-1252">
</head>
<body dir="auto">
<div></div>
<div>That's why I've included the &quot;case ... where&quot; case :) condition3 is only evaluated after 1/2.</div>
<div><br>
On 14 Dec 2015, at 12:59, Marc Knaup &lt;<a href="mailto:marc@knaup.koeln">marc@knaup.koeln</a>&gt; wrote:<br>
<br>
</div>
<blockquote type="cite">
<div>
<div dir="ltr">This changes the behavior though.
<div><br>
</div>
<div>In &quot;<font face="monospace, monospace">if cond1 &amp;&amp; cond2</font>&quot; cond2 is only evaluated iff cond1 is true.</div>
<div>Using switch both conditions will be evaluated right away unconditionally.</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Mon, Dec 14, 2015 at 12:48 PM, Etan Kissling via swift-evolution
<span dir="ltr">&lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt;</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>Counter-proposal that eliminates the nested ifs.</div>
<div><br>
</div>
If I have functions with long if blocks, I typically use switches on named tuples.
<div><br>
</div>
<div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="color:rgb(187,44,162)">switch</span>&nbsp;(condition1:&nbsp;..., condition2: ...) {</div>
</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)">case</span>&nbsp;(condition1:&nbsp;<span style="color:rgb(187,44,162)">false</span>, condition2:&nbsp;<span style="color:rgb(187,44,162)">true</span>):</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">&nbsp; &nbsp; &nbsp; &nbsp; ...</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br>
</div>
<div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo">&nbsp; &nbsp;&nbsp;<span style="color:rgb(187,44,162)">case</span>&nbsp;(condition1:&nbsp;<span style="color:rgb(187,44,162)">_</span>, condition2:&nbsp;<span style="color:rgb(187,44,162)">false</span>):</div>
<div><span style="font-family:Menlo;font-size:11px">&nbsp; &nbsp; &nbsp; &nbsp; ...</span></div>
<div><span style="font-family:Menlo;font-size:11px"><br>
</span></div>
<div><span style="font-family:Menlo;font-size:11px">&nbsp; &nbsp;&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">case</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px">(condition1:</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">true</span><span style="font-family:Menlo;font-size:11px">,
 condition2:</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">true</span><span style="font-family:Menlo;font-size:11px">)&nbsp;</span><span style="color:rgb(187,44,162);font-family:Menlo;font-size:11px">where&nbsp;</span><span style="font-family:Menlo;font-size:11px">condition3</span><span style="font-family:Menlo;font-size:11px">:</span></div>
<div><span style="font-family:Menlo;font-size:11px">&nbsp; &nbsp; &nbsp; &nbsp; ...</span></div>
<div><span style="font-family:Menlo;font-size:11px"><br>
</span></div>
<div>
<div><span style="font-family:Menlo;font-size:11px">&nbsp; &nbsp;&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">case</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px">(condition1:</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">true</span><span style="font-family:Menlo;font-size:11px">,
 condition2:</span><span style="font-family:Menlo;font-size:11px">&nbsp;</span><span style="font-family:Menlo;font-size:11px;color:rgb(187,44,162)">true</span><span style="font-family:Menlo;font-size:11px">)</span><span style="font-family:Menlo;font-size:11px">:</span></div>
<div><span style="font-family:Menlo;font-size:11px">&nbsp; &nbsp; &nbsp; &nbsp; ...</span></div>
</div>
<div><span style="font-family:Menlo;font-size:11px">}</span></div>
<div><br>
</div>
<div>This way, you are reminded after each long block about your current scope, and the compiler checks for unhandled cases.</div>
<div><br>
</div>
<div>Etan</div>
<div><br>
</div>
<div><br>
</div>
<div>
<blockquote type="cite">
<div>
<div class="h5">
<div>On 12 Dec 2015, at 22:35, Greg Parker via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div>
<br>
</div>
</div>
<div>
<div style="word-wrap:break-word">
<div>
<div class="h5"><br>
<div>
<blockquote type="cite">
<div>On Dec 12, 2015, at 5:41 AM, Al Skipp via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div>
<div>
<div style="word-wrap:break-word"><br>
<div>
<blockquote type="cite">
<div>On 12 Dec 2015, at 13:31, Marc Knaup via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>&gt; wrote:</div>
<br>
<div><span style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I'm
 also against any kind of markers to annotate the end of a block.</span>
<div style="font-family:Helvetica;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;line-height:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">
<br>
<div>If the code inside a if/guard/loop/do/func/var/… block is so long that the developer thinks about annotating the closing curly brace then they should instead break it down into smaller pieces. Move parts into separate functions and replace it with calls
 to these functions.</div>
<div>This makes the block shorter, much easier to understand and the function names will aid as additional documentation.</div>
</div>
</div>
</blockquote>
</div>
<br>
<div>I completely agree.&nbsp;</div>
<div><br>
</div>
<div>If code becomes so impenetrable that you need to annotate the end of blocks to assist comprehension, then the code needs refactoring.</div>
</div>
</div>
</blockquote>
<br>
</div>
<div>Or a better editor. Modern code editors have affordances to improve readability of such code, such as highlighting matching braces, coloring nested scopes, or folding and unfolding scopes.</div>
<div><br>
</div>
<div>One advantage of the editor-based approaches is that they don't make editing more difficult. You don't need to write any scope annotations and you don't need to keep them up to date as the code changes.</div>
<div><br>
</div>
<div><br>
</div>
<div>--&nbsp;</div>
<div>Greg Parker &nbsp; &nbsp; <a href="mailto:gparker@apple.com" target="_blank">gparker@apple.com</a>&nbsp; &nbsp; &nbsp;Runtime Wrangler</div>
<div><br>
</div>
<br>
</div>
</div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rsy1Rfl-2F2nC7NpxylSH-2Flg4L34JAyM2h5gKACTYteuNZjgzFkOJErGPAz1KFQTfA5gHDYbANUskVGjcZcBEoEeFiw0xJFSRSbc-2BOvEjHSxkhHW1iKRr-2FDtwvPdiuA09jcY6863lbQ5KAcYIgi31tpFf3gF6rZNtE39Rgx-2Fo8VjFT98MHe-2BjD4Q8YN9N-2B0zxIC0-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0!important;margin-top:0!important;margin-bottom:0!important;margin-right:0!important;margin-left:0!important;padding-top:0!important;padding-bottom:0!important;padding-right:0!important;padding-left:0!important">
</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>
</div>
</blockquote>
</body>
</html>