<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 5, 2015, at 10:13 AM, David Owens II &lt;<a href="mailto:david@owensd.io" class="">david@owensd.io</a>&gt; wrote:</div><br class="Apple-interchange-newline"><div class=""><div 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;">Is there a reason we cannot use labelled case statements?</div><div 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;"><br class=""></div><div 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;">&nbsp; &nbsp; switch some_value {<br class="">&nbsp; &nbsp; case .REFINED:<br class="">&nbsp; &nbsp; &nbsp; &nbsp; if !validate(some_value) { return NULL }<br class="">&nbsp; &nbsp; &nbsp; &nbsp; fallthrough base</div><div 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;"><br class="">&nbsp; &nbsp; base: case .BASE:<br class="">&nbsp; &nbsp; &nbsp; &nbsp; handle_enum_value();<br class="">&nbsp; &nbsp; }</div><div 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;"><br class=""></div><div 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;">At least this is explicit now.</div></div></blockquote><div><br class=""></div>Yeah, maybe there's a more general language feature that could replace 'fallthrough' here. Instead of labelling cases, we could support a 'reswitch' statement that redispatches the switch to the case matching the operand:</div><div><br class=""></div><div>&nbsp; &nbsp; switch some_value {<br class="">&nbsp; &nbsp; case .REFINED:<br class="">&nbsp; &nbsp; &nbsp; &nbsp; if !validate(some_value) { return NULL }<br class="">&nbsp; &nbsp; &nbsp; &nbsp; reswitch .BASE<br class=""><br class="">&nbsp; &nbsp; case .BASE:<br class="">&nbsp; &nbsp; &nbsp; &nbsp; handle_enum_value();<br class="">&nbsp; &nbsp; }<br class=""><br class=""></div><div>That should be easy to peephole to a proper fallthrough in constant cases, but would also nicely generalize to applications like interpreters, where it's often desirable to push the dispatch inline into the logic for better pipelining.</div><div><br class=""></div><div>-Joe</div><div><br class=""><blockquote type="cite" class=""><div class=""><div 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;"><br class=""></div><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=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 10:04 AM, Vinicius Vendramini &lt;<a href="mailto:vinivendra@gmail.com" class="">vinivendra@gmail.com</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;"><div class="">I understand there might be some cases in which the syntax provided is indeed useful for experienced programmers writing their code. However, in almost all the examples here, I had to struggle to understand the logic behind the code. Not because it’s poorly written... probably because this syntax may be used for many different purposes, so it’s hard to get what exactly is the intent behind each use.</div><div class=""><br class=""></div><div class="">In Pierre’s latest example, for instance, it took me a few seconds to understand what was going on. I know it’s a simplified case, but it seems clearer to me to just write something like</div><div class=""><br class=""></div><div class="">if some_value == .Refined &amp;&amp; !validate(some_value) {</div><div class=""><span class="Apple-tab-span" style="white-space: pre;">        </span>return NULL</div><div class="">}</div><div class="">handle_enum_value()</div><div class=""><br class=""></div><div class="">More complex cases make for a better argument for `switch`es, mainly because they avoid big `if` pyramids, but especially in those I feel the resulting code is significantly harder to understand.</div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On Dec 5, 2015, at 12:15 PM, Pierre Habouzit &lt;<a href="mailto:phabouzit@apple.com" class="">phabouzit@apple.com</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 5, 2015, at 9:02 AM, Chris Lattner &lt;<a href="mailto:clattner@apple.com" class="">clattner@apple.com</a>&gt; wrote:<br class=""><br class="">On Dec 4, 2015, at 2:05 PM,<span class="Apple-converted-space">&nbsp;</span><a href="mailto:jalkut@red-sweater.com" class="">jalkut@red-sweater.com</a><span class="Apple-converted-space">&nbsp;</span>wrote:<br class=""><blockquote type="cite" class="">In the spirit of some other proposals that remove C or C++ style artifacts, what do folks think about the possibility of removing the "fallthrough" keyword from the language?<br class=""></blockquote><br class="">I’m not making an argument either way, but I want to point something out: there is a major difference between fallthrough vs ++/c-style-for. &nbsp;To someone who doesn’t know them, the later are "syntactic magic” with no reasonable way to&nbsp;decipher other than looking them up somewhere. &nbsp;The former is an English word whose meaning is obvious in context.<br class=""><br class="">All I’m saying is that to a reader of code, the “badness” of ++ and c-style for loops is greater than the “badness" of fallthrough.<br class=""></blockquote><br class=""><div class="">Given that Swift has the goal to also be a low level language, fallthrough is really useful for conciseness and readability.</div><div class=""><br class=""></div><div class="">in system programming C, I find myself writing things like this very often:</div><div class=""><br class=""></div><div class=""><br class=""></div><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">switch (some_value) {</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">case ENUM_VALUE_REFINED:</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; if (validate(some_value)) {</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; return NULL;</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; }</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; /* fallthrough */</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">case ENUM_VALUE_BASE:</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; handle_enum_value();</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp;&nbsp;…</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">}</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><br class=""></blockquote>Where the swift equivalent would roughly be:<br class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><div class=""><br class=""></div><div class=""><font face="Menlo" class="">switch some_value {</font></div><div class=""><font face="Menlo" class="">case .REFINED:</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; if !validate(some_value) { return NULL }</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; fallthrough</font></div><div class=""><font face="Menlo" class="">case .BASE:</font></div><div class=""><font face="Menlo" class="">&nbsp; &nbsp; handle_enum_value();</font></div><div class=""><font face="Menlo" class="">}</font></div></blockquote><br class=""><div class="">This is as readable as it gets and is a pattern that the libdispatch has in several places e.g.</div><div class=""><br class=""></div><div class="">Of course, you cannot fall through to arbitrary cases, so things like this C code cannot be done in swift:</div><div class=""><br class=""></div><div class=""><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">switch (some_value) {</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">case ENUM_VALUE_REFINED_1:</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">&nbsp; &nbsp; if (validate(some_value)) {</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; return NULL;</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp;</font><span class="" style="font-family: Menlo;">&nbsp; &nbsp;}</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">&nbsp; &nbsp; goto base_value;</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">case ENUM_VALUE_REFINED_2:</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">&nbsp; &nbsp; if (validate(some_value)) {</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; &nbsp; &nbsp; return NULL;</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp;</font><span class="" style="font-family: Menlo;">&nbsp; &nbsp;}</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">&nbsp; &nbsp; goto base_value;</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;"><br class=""></span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><span class="" style="font-family: Menlo;">case ENUM_VALUE_BASE:</span></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">base_value:</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp; handle_enum_value();</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">&nbsp; &nbsp;&nbsp;…</font></blockquote><blockquote class="" style="margin: 0px 0px 0px 40px; border: none; padding: 0px;"><font face="Menlo" class="">}</font></blockquote></div><div class=""><font face="Menlo" class=""><br class=""></font></div><div class=""><br class=""></div><div class="">cannot be written in swift, despite also being quite useful.</div><div class=""><br class=""></div><div class="">Jumping between arbitrary points inside a switch is disgusting. jumping from label to label is useful and not harmful especially in swift where you can’t place code between the “switch” and the first case.</div><div class=""><br class=""></div><div class="">-Pierre</div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=LFwSuj9FMv8p5lHRk78JpoTG6TdqPOb6ZXyNv3YIC3zVDOh8SFmEynnCFkZSU96i9QOrOOTyNxaypltLlSJqLIZdWsED-2BOMeJdGYkJjC7ncF2Xa2dkhlZN0W2Ze0g-2BfyoGT9FF6mkqHPUUfRquNLw79AGIbmVY0a3LpUa2jsib6wiFWIzHuPN7I6CZVx0FEp6-2FnUBsFTulUc6c1bw4PUnm6wkUbE8SeHhxQCkvAyzK8-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><br class=""></div></blockquote></div><br class=""><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=nE9rxSXA5G4kxsTVkgv43pXkLx-2B36P-2BPNJufHeY0dgfEnSrTiflGiTqLfYLhLg624kToIkI0RhrFjsk0TyglfEmpl9ujuhls2gfK5hl8AeRlCjJ-2BoFHUvE8L8GnwiICsBRMYm224aw6wlGWfoEMwIxTmok3Eu2lY32Pz-2BfgmhDQtrJ2-2BJIkkH4ku1XDuJewD869cNDDaUp6bsK1hIti0MQ-3D-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><br class=""></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;"><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=RoDF4MveSEMYBIqIJA6ub1g8cOZ-2BVYvqV-2FqygPhjPn-2BrYUQN4Tsevg-2Fhmp6N0YiqQlnjS-2BGombsh3oLD41ooXV6k49mX1IYIe14-2BjuY1O7Ld1v7RjKkqZMLZq0kV-2BQxwkz53yWUHJGc70p75Mftqyjc8KDo2XIkjpdNtXIKmZO5IUfha2CLU1-2FGxfWUG9K93qQIfWIGrlpqgIaCiLmbTWQHIwMGsutFnpVXK6GIDg3Q-3D" alt="" width="1" height="1" border="0" 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; height: 1px !important; width: 1px !important; border-width: 0px !important; margin: 0px !important; padding: 0px !important;" class=""><span 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; float: none; display: inline !important;" class=""><span class="Apple-converted-space">&nbsp;</span>_______________________________________________</span><br 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=""><span 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; float: none; display: inline !important;" class="">swift-evolution mailing list</span><br 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=""><a href="mailto:swift-evolution@swift.org" 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="">swift-evolution@swift.org</a><br 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=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" 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="">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br class=""></body></html>