<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="">Hi Reviewers,</div><br class=""><div><div>Since it looks like Nate has already done that analysis for the standard library, let’s analyze Dmitri's semi-obfuscated prime signature for fun. &nbsp;</div><div><br class=""></div><div>Starting with:</div><div><br class=""></div><div>main(i,j){for(i=2;;i++){for(j=2;j&lt;i;j++){if(!(i%j)){j=0;break;}}if<br class="">(j){printf("%d\n",i);}}} /*Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;*/</div><div><br class=""></div><div>First transform into Swift. &nbsp;(Using += 1 instead of ++ since we know those are going.)</div><div><br class=""></div><div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">var</span> j: Int</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">for</span> <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">var</span> i=<span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">2</span>; ; i+=<span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">1</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">for</span> <span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j</span>=<span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">2</span>; <span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j</span>&lt;i; <span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j</span>+=<span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">1</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">if</span> i%<span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j</span> == <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j&nbsp;</span>=&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">break</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">if</span> <span style="font-variant-ligatures: no-common-ligatures; color: #539aa4" class="">j</span> != <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(i)</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">}&nbsp;<span style="color: rgb(29, 148, 33);" class="">// Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Helvetica; font-size: 12px;" class=""><br class=""></span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-family: Helvetica; font-size: 12px;" class="">Next get rid of those for loops. &nbsp;</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;"><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class=""><span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">for</span> i <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">in</span> <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">2</span> ..&lt;&nbsp;<span style="font-variant-ligatures: no-common-ligatures; color: #703daa" class="">Int</span>.max {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">var</span> j = <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">2</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">while</span> j &lt; i {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">if</span> i%j == <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; j = <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">break</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; j += <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">1</span></div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #c32275" class="">if</span> j != <span style="font-variant-ligatures: no-common-ligatures; color: #0435ff" class="">0</span> {</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; &nbsp; <span style="font-variant-ligatures: no-common-ligatures; color: #3d1d81" class="">print</span>(i)</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">&nbsp; }</div><div style="margin: 0px; font-size: 18px; line-height: normal; font-family: Menlo;" class="">}&nbsp;<span style="color: rgb(29, 148, 33);" class="">// Dmitri Gribenko &lt;<a href="mailto:gribozavr@gmail.com" class="">gribozavr@gmail.com</a>&gt;</span></div></div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;">There is an improvement in that it forced us to avoid integer overflow by specifying the end game (although the heat death of the universe might happen first if you run this in a playground). &nbsp;Since j escapes the scope of it’s loop we couldn’t use a for statement variable. &nbsp;I think this is actually a good thing because it makes this wrinkle more apparent.</div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;">For-in almost always looks better. If things get too complicated you can always fall back to a different control structure like while or repeat. &nbsp; &nbsp;BTW, looking at Doug’s implementation of the Sieve of Eratosthenes from his WWDC Value-Types talk, it uses &nbsp;for-in-stride. &nbsp;He explicitly preferred that to a traditional C-style even though it would have been easy to go either way. &nbsp;It just looks better. &nbsp;Fewer semicolons, it must be good.</div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;">Here is my review:</div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;">1. I endorse the proposal</div><div style="font-family: Helvetica; font-size: 12px;">2. I think it is worthwhile as it will force people to adopt good practices early and break bad habits.</div><div style="font-family: Helvetica; font-size: 12px;">3. I believe the change goes along well with the removal of ++ and — operator. &nbsp;Reducing the surface area of the language is a good thing.</div><div style="font-family: Helvetica; font-size: 12px;">4. It will cause the “Swift is not stable!” crowd to go a little more crazy but I am okay with that.</div><div style="font-family: Helvetica; font-size: 12px;">5. I thought about this pretty hard, checked my usage of for loops in a non-trivial code base. &nbsp;I feel even more comfortable after Nate’s analysis of the standard library.</div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div><div style="font-family: Helvetica; font-size: 12px;">PS: &nbsp;I do not recommend any changes to Dmitri's signature. :)</div><div style="font-family: Helvetica; font-size: 12px;"><br class=""></div></div></div></div></body></html>