<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="">It doesn't need to be an underscore, but when it is not, the compiler emits an educative warning steering you towards _:<div class=""><br class=""></div><div class=""><div style="margin: 0px; font-size: 11px; line-height: normal; font-family: Consolas;" class=""><b class="">/tmp/test.swift:3:7: </b><span style="font-variant-ligatures: no-common-ligatures; color: #a837a5" class=""><b class="">warning: </b></span><b class="">immutable value 'i' was never used; consider replacing with '_' or removing it</b></div></div><div class=""><br class=""></div><div class="">You can also use inclusive ranges instead if you're more comfortable with that: 1...5000 will do just that.</div><div class=""><br class=""></div><div class="">I don't mean to come across as dismissive, and I'm all for an inclusive Swift that you can pick up without knowing advanced concepts. However, there is definitely value in helping people learn, and learning always moves you a little bit out of your comfort zone. When do we remove the training wheels? How long can we hide the fact that indices usually start at 0? How long before you need to iterate an array using the same range-based for loop?</div><div class=""><br class=""></div><div class="">I spend a lot of time on Stack Overflow and I've seen lots of beginners ask for lots of things, but the people who ask about the for loop are usually people with a background in another C-like language who try to use the arguably less readable C-like for loop. I've never seen anyone before say that it looks unclean or unreadable.</div><div class="">
<br class=""><div><blockquote type="cite" class=""><div class="">Le 18 déc. 2015 à 13:38:59, Cihat Gündüz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</a>&gt; a écrit :</div><br class="Apple-interchange-newline"><div class=""><span style="font-family: LucidaGrande; 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="">I agree with both of you about the alternative implementations.</span><div class="" style="font-family: LucidaGrande; 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: LucidaGrande; 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;">That’s exactly what I’d love to see integrated to the standard library like Ruby is here:<div class=""><a href="http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times" class="">http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times</a></div><div class=""><br class=""></div><div class="">My main problem is that it neither looks<span class="Apple-converted-space">&nbsp;</span><b class="">clean</b><span class="Apple-converted-space">&nbsp;</span>nor<span class="Apple-converted-space">&nbsp;</span><b class="">readable</b><span class="Apple-converted-space">&nbsp;</span>especially for beginners that there is an<span class="Apple-converted-space">&nbsp;</span><i class="">underscore</i><span class="Apple-converted-space">&nbsp;</span>in the closure. Also beginners often get confused with the number of times some code is run when<span class="Apple-converted-space">&nbsp;</span><i class="">starting to count from 0</i><span class="Apple-converted-space">&nbsp;</span>which is also why I think it shouldn’t appear. The .times method would solve both of these problems.</div><div class=""><br class=""><div class=""><blockquote type="cite" class=""><div class="">Am 18.12.2015 um 19:33 schrieb Etan Kissling &lt;<a href="mailto:kissling@oberon.ch" class="">kissling@oberon.ch</a>&gt;:</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;">(or with a for in loop &nbsp;-- but i guess you have a reason for using .foreach)<div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">for</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0</span>..&lt;<span class="" style="color: rgb(39, 42, 216);">5_000</span><span class="Apple-converted-space">&nbsp;</span>{</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(61, 29, 129);">print</span>(<span class="" style="color: rgb(209, 47, 27);">"asdf"</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class=""><br class=""></div><div class=""><br class=""></div><div class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 19:31, Etan Kissling via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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="">You don't need stride for this.</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>foo() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; (<span class="" style="color: rgb(39, 42, 216);">0</span>..&lt;<span class="" style="color: rgb(39, 42, 216);">5_000</span>).<span class="" style="color: rgb(61, 29, 129);">forEach</span><span class="Apple-converted-space">&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(61, 29, 129);">print</span>(<span class="" style="color: rgb(209, 47, 27);">"asdf"</span>)</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class=""><br class=""></div><br class=""><div class=""><blockquote type="cite" class=""><div class="">On 18 Dec 2015, at 19:25, Cihat Gündüz via swift-evolution &lt;<a href="mailto:swift-evolution@swift.org" class="">swift-evolution@swift.org</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;">Dear Swift-Community,<div class=""><br class=""></div><div class="">I’d like to propose an<span class="Apple-converted-space">&nbsp;</span><b class="">addition of a useful method</b>, especially for beginners that also makes Swift much more readable in some situations: The addition of a .times method to Integer type(s).</div><div class=""><br class=""></div><div class="">For example recently in one of my projects I wanted to test the scalability of an important piece of code and wrote this method:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">func</span><span class="Apple-converted-space">&nbsp;</span>testPerfQualityInPercentWithoutQualityImprovements() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><span class="">&nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span></span><span class="" style="color: rgb(187, 44, 162);">self</span><span class="">.</span>measureBlock<span class=""><span class="Apple-converted-space">&nbsp;</span>{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">let</span><span class="Apple-converted-space">&nbsp;</span>expectedQuality =<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">33.33</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0</span>.<span class="" style="color: rgb(61, 29, 129);">stride</span>(to:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">5_000</span>, by:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">1</span>).<span class="" style="color: rgb(61, 29, 129);">forEach&nbsp;</span>{<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">_</span><span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">in</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(49, 89, 93);">XCTAssertEqualWithAccuracy</span>(<span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">crossword</span>.<span class="" style="color: rgb(79, 129, 135);">qualityInPercent</span>, expectedQuality, accuracy:<span class="Apple-converted-space">&nbsp;</span><span class="" style="color: rgb(39, 42, 216);">0.1</span>) &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; }</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class=""><br class=""></div><div class="">As you can see what I basically wanted was to repeat the test some thousand times. I also like to use the Ruby language and one thing I love about it is that it has some really handy methods integrated to the language in situations like this which make the code very readable and therefore fun to use.</div><div class=""><br class=""></div><div class="">I’m an even bigger fan of Swift so I’d love to see such useful methods appear in Swift, too and this is the first I came across that I really missed. So I’m asking myself, what if I could write the same code above like this:</div><div class=""><br class=""></div><div class=""><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">func</span>&nbsp;testPerfQualityInPercentWithoutQualityImprovements() {</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo; color: rgb(49, 89, 93);"><span class="">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;</span><span class="" style="color: rgb(187, 44, 162);">self</span><span class="">.</span>measureBlock<span class="">&nbsp;{</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(187, 44, 162);">let</span>&nbsp;expectedQuality =&nbsp;<span class="" style="color: rgb(39, 42, 216);">33.33</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(39, 42, 216);">5_000.times {</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&nbsp;<span class="" style="color: rgb(49, 89, 93);">XCTAssertEqualWithAccuracy</span>(<span class="" style="color: rgb(187, 44, 162);">self</span>.<span class="" style="color: rgb(79, 129, 135);">crossword</span>.<span class="" style="color: rgb(79, 129, 135);">qualityInPercent</span>, expectedQuality, accuracy:&nbsp;<span class="" style="color: rgb(39, 42, 216);">0.1</span>) &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; } &nbsp;&nbsp;</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; &nbsp; &nbsp;&nbsp;}</div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;">&nbsp; &nbsp; }</div></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><br class=""></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">I think it could be added to the Swift standard library very easily (for example by using the .stride method like I used) without any side effects and has enough advantages to be part of Swift itself. What do you think?</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">I wish you all the best,</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;">Cihat</span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; font-size: 11px; line-height: normal; font-family: Menlo;"><span class="" style="font-family: Helvetica; font-size: 12px;"><br class=""></span></div><div class="" style="margin: 0px; line-height: normal;">P.S.: This is my very first mail in such a mailing list so I did everything correctly. ^.^</div><div class="" style="margin: 0px; line-height: normal;"><br class=""></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rv24uhtvYv57b57RThnoUBESAxxMDy12HfxuT9sf9VVp3u-2BljgFoOV9Ju-2BtFhXXJ1d8nr-2FYw-2FUNbKUk26rHfCj9zunav26wrq76QmN2VjrXsxpGqGynDLjQOq3xzG0kPrAlahxwYVVKYxWr-2FixGS8o60s13y8Z-2BEl3Y7elh5Tr-2F9t3iW87Nn3MFjpz-2FOHvhx30-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=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rudyoy59P95VIFCXE8vsNIm3CRv2xeSfRQi24G3J7csJAwXsAU0KgdqyUmTpkPgjbX8d25r2mfuva9tzq-2FUDdol4HlpIh-2BHPdrv3VJ3o4xk2ghsZ6aTSUz-2FXhHLeKnEcHzsL3XLw-2F2NTNaky7syxtgWh87TGLUN5goHMjwNXVFxk5QMxUtPLGjvJKyN7d4juEc-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=""></div></div></div></blockquote></div><br class=""></div></div><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=iRI3beHTe3UxYAHTlV3lA38zIPfHMhyuRzgTmGKV6k5S-2FLtOx-2BROGe-2FfDGB7KyDwaSL5P9-2BQYbNCvB4d-2Fg-2FAGO-2B8G50u32Zw385KkcxuO7qNmVKW7I496YMBCouPCudO5YM5ndlvKpCwHuceW-2Boheqo2q1GmMyZY721sY1RDE5zaf7YsPX0tvelGghtlQo-2FsN05fW0bSNYDKsb0crPSrfCPGkrcYKe4OfQ-2Fe9zOVsXs-3D" alt="" width="1" height="1" border="0" style="font-family: LucidaGrande; 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: LucidaGrande; 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><span style="font-family: LucidaGrande; 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><br style="font-family: LucidaGrande; 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: LucidaGrande; 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: LucidaGrande; 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: LucidaGrande; 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: LucidaGrande; 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: LucidaGrande; 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=""></div></body></html>