<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><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 2:33 PM, Kevin Ballard <<a href="mailto:kevin@sb.org" class="">kevin@sb.org</a>> wrote:</div><div class=""><div class=""><div class="">It's not actually Duff's Device. Duff's Device relies on the fact that C switch statements don't actually introduce a new scope, and so it overlaps a switch with a do-while loop. This lets it only test the number of bytes once, to jump into the middle of the loop, and then it switches over to a while loop that decrements a counter every 8 instructions. Basically, it's a trick for manual loop unrolling that deals with non-multiple-of-8 counts efficiently.<br class=""></div>
</div></div></blockquote><div><br class=""></div>To be pedantic, C switch statements do introduce a new scope. What Duff’s Device exploits is that switch is allowed to jump into (almost) arbitrary scopes, and cases can appear anywhere recursively inside a switch.</div><div><br class=""></div><div>But your point that Swift’s switch requires cases to be at the top level within a switch and thus prevents the use of Duff’s Device is 100% correct.</div><div><br class=""></div><div>John.</div><div><br class=""><blockquote type="cite" class=""><div class=""><div class=""><div class=""> </div>
<div class="">Steve's code is also an example of manual loop unrolling that deals with non-multiple-of-8 counts, but it has calculate the number of bytes on every iteration instead of once. It's a good example of one of the uses of `fallthrough`, it's just not Duff's Device. It's impossible to use Duff's Device in Swift.<br class=""></div>
<div class=""> </div>
<div class="">-Kevin Ballard</div>
<div class=""> </div>
<div class="">On Fri, Dec 4, 2015, at 02:16 PM, Greg Titus wrote:<br class=""></div>
<blockquote type="cite" class=""><div class="">Streza’s source code is an example of Duff’s Device, which is a big place where switch fallthrough is arguably the cleanest way to do things and the reason why I’d personally prefer to keep it as part of the language.<br class=""></div>
<div class=""> </div>
<div class=""><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 2:12 PM, Erica Sadun <<a href="mailto:erica@ericasadun.com" class="">erica@ericasadun.com</a>> wrote:<br class=""></div>
<div class=""> </div>
<div class=""><div style="word-wrap:break-word;-webkit-line-break:after-white-space;" class=""><div class="">Oh let it die, let it die. Any time I use fallthrough I find myself re-factoring to stop using it. <br class=""></div>
<div class=""> </div>
<div class=""><b class="">True fact</b>: On all of <a href="http://gist.github.com/" class="">gist.github.com</a>, there are only 22 gist results for "fallthrough language:swift".<br class=""></div>
<div class="">Half of those are people just testing out the feature. Most of the remaining ones are just complex cases:<br class=""></div>
<div class=""><i class="">case .Enum1, .Enum2:</i><br class=""></div>
<div class="">expressed as <br class=""></div>
<div class=""><i class="">case .Enum1: fallthrough</i><br class=""></div>
<div class=""><i class="">case .Enum2:</i><br class=""></div>
<div class=""> </div>
<div class="">And then there's streza: <a href="https://gist.github.com/stevestreza/2557dc5ec9e7c694d7ea" class="">https://gist.github.com/stevestreza/2557dc5ec9e7c694d7ea</a> I'm pretty sure that ponies were harmed in the production of whatever that last bit is.<br class=""></div>
<div class=""> </div>
<div class=""> </div>
<div class=""> </div>
<div class=""> </div>
<div class=""><blockquote type="cite" class=""><div class="">On Dec 4, 2015, at 3:05 PM, <a href="mailto:jalkut@red-sweater.com" class="">jalkut@red-sweater.com</a> wrote:<br class=""></div>
<div class=""> </div>
<div class=""><div class=""><div 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=""></div>
<div class=""> </div>
<div class="">My understanding is this keyword is only used for the archaic seeming purpose of perpetuating C-style fallthrough from one switch statement to the subsequent one. The documentation hedges the use of this keyword in forbidding terms that make it clear its use is not encouraged. The presence of the keyword, while an improvement over C’s implicit fallthrough, is a mark of inelegance on an otherwise well-designed, opinionated implementation of swtich statements.<br class=""></div>
<div class=""> </div>
<div class="">The ugliness of fallthrough’s C-style behavior even demands a caveat in the documentation:<br class=""></div>
<div class=""> </div>
<div class="">"The fallthrough keyword does not check the case conditions for the switch case that it causes execution to fall into. The fallthrough keyword simply causes code execution to move directly to the statements inside the next case (or default case) block, as in C’s standard switch statement behavior."<br class=""></div>
<div class=""> </div>
<div class="">To my mind, the caveat explains just what is wrong with fallthrough, both in C or Swift: coded that is clearly labeled with deliberate conditions can nonetheless be reached.<br class=""></div>
<div class=""> </div>
<div class="">I quipped about this on Twitter, and the most common pushback I got seemed to be from people who either did not know about Swift’s support for comma-separated case statements, or harbored an aesthetic preference for clustering such cases together with fallthrough statements.<br class=""></div>
<div class=""> </div>
<div class="">In my opinion, unless somebody can think of a strong defense for supporting intentional fallthrough in Swift, removing the keyword would be a move in the direction of minimizing the language’s complexity while also discouraging poor coding style in switch statements.<br class=""></div>
<div class=""> </div>
<div class="">Thoughts?<br class=""></div>
<div class=""> </div>
<div class="">Daniel<br class=""></div>
<div class=""> </div>
<div class="">_______________________________________________<br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</div>
</div>
</blockquote></div>
<div class=""> </div>
<div class=""> <img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/989cb4366ad41b4455cc3f50f9b71777dbe9035cdabeb439a2cbe058c39f9d97/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d33757732745b446d22364f4368776b4e4749665f6b636e4447513e6a7469514948537938614931365f49435d2236437264485d4d223647664c6a505a58416a4a7b623341545d6165725b6750524145507a695767683b626c6235326430743252446c61313a46477d4154424c4357513454793d2232475366637a774349466a76603d40545d223248415142686e4f63723a745a747d22364a6a647850515f4d4859696f684b64796346526a6a697336616a79667a6e626a73545a47664a76323979434d22364d4d496f6a7251407779685557624c6867425c435563707c603e697868366969587d22364a705341677473783d22364444794a666d22324a64337d23344/open" class=""><br class=""></div>
</div>
<div class="">_______________________________________________<br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div class=""><a href="https://lists.swift.org/mailman/listinfo/swift-evolution" class="">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br class=""></div>
</div>
</blockquote></div>
<div class=""> </div>
<div class=""> <img style="height:1px !important;width:1px !important;border-top-width:0px !important;border-right-width:0px !important;border-bottom-width:0px !important;border-left-width:0px !important;margin-top:0px !important;margin-bottom:0px !important;margin-right:0px !important;margin-left:0px !important;padding-top:0px !important;padding-bottom:0px !important;padding-right:0px !important;padding-left:0px !important;" border="0" height="1" width="1" alt="" src="https://www.fastmailusercontent.com/proxy/0d75881f7eb3107ead080b1f6943e0dd834cb1b283f5f5c0a1e946f921f2e73d/8647470737a3f2f25723030323431303e23647e23756e64676279646e2e65647f27766f2f60756e6f35707e6d3148765176786c673171614a7d2236454230345272776e475e647744503a5c6c6a684b6636317933335239366555394a4d646777624966375466315c6d6362676541363c635f4653664757384c427072636a444a77387c62315d2236465d4e6161323833367469305b63457d22364a655e634e6567445236603d2236457745434a70707f4745544276633570756160365e636a4d657d6a52696e63615c617f457e6d22364a584c6e6369794539563c6b6b687f665d223643723b675238545077745d223244527a5552466f49444134785d49433e4f4c474e6867345152697036324b6a677d23344d23344/open" class=""><br class=""></div>
<div class=""><u class="">_______________________________________________</u><br class=""></div>
<div class="">swift-evolution mailing list<br class=""></div>
<div class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class=""></div>
<div 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 class=""> </div>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=hWKWvOREWCPT32eVzNXOV7yIWXgGOvlMtgjKbOieJnb8EwzmKs3H-2FHCKlv4ilHZMtZj0FLR2TNORrxqF3WP-2FKzg0kPDAN4899q9uganv-2BwZp2lTqLfjBXjvTf1i4kDkUZ19Q6tVnOggTdHi5iejWc1DkHDk3GK1cqYvovVthFeGR1qlubx6BWnccL0xwpf9eH2FSYxCNHf8HThnmimMRr02it-2BrSoAkn7Fi9EaJnun4-3D" alt="" width="1" height="1" border="0" style="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;" class="">
</div>
_______________________________________________<br class="">swift-evolution mailing list<br class=""><a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a><br class="">https://lists.swift.org/mailman/listinfo/swift-evolution<br class=""></div></blockquote></div><br class=""></body></html>