<div dir="ltr">I like how clean "100.times { doSomething() }" looks, but I'm concerned its usefulness will be limited because control-flow statements like break/continue/return won't work from inside a closure.<div class="gmail_extra"><br clear="all"><div><div class="gmail_signature"><div dir="ltr"><div>Jacob<br></div></div></div></div>
<br><div class="gmail_quote">On Fri, Dec 18, 2015 at 11:36 AM, Cihat Gündüz <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></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"><br><div><span class=""><blockquote type="cite"><div>Am 18.12.2015 um 20:13 schrieb Félix Cloutier <<a href="mailto:felixcca@yahoo.ca" target="_blank">felixcca@yahoo.ca</a>>:</div><br><div><div style="word-wrap:break-word">It doesn't need to be an underscore, but when it is not, the compiler emits an educative warning steering you towards _:</div></div></blockquote><div><br></div></span><div>It’s not about the underscore as a character, it’s about the fact that there is the clutter of an underscore at all what I don’t like and what makes me feel the code isn’t as clean as it could be.</div><span class=""><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Consolas"><b>/tmp/test.swift:3:7: </b><span style="color:#a837a5"><b>warning: </b></span><b>immutable value 'i' was never used; consider replacing with '_' or removing it</b></div></div><div><br></div><div>You can also use inclusive ranges instead if you're more comfortable with that: 1...5000 will do just that.</div></div></div></blockquote><div><br></div></span><div>I’m comfortable with ranges but I also used to teach Java back a few years ago and I saw computer science students struggle with the exact number a loop was being executed. So that’s the only reason I brought up that example to have an additional argument.</div><div><br></div><div>But again, for me it is more about the clutter that the 1… or 0..< adds to something that could so easily made simpler and more descriptive.</div><div><br></div><div>I think this is also a question of: <i>How many convenience methods do we want to see in the Swift standard library?</i> In Ruby, at least, there seemed to be enough people to find this one useful. And it’s the first method I missed until now, so I took that as a sign before suggesting the addition. I also don’t like when there are thousands of convenience methods for things that could easily be written in other ways – but I don’t feel that way with the suggested .times method.</div><span class=""><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div><br></div><div>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><br></div><div>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></div></blockquote><div><br></div></span><div>I understand what you mean but I don’t think that this is about indices or beginners. The fact that readability and expressiveness make a language easier to learn for beginners IMHO is just a side effect of a well thought-out and developed language. Maybe I wasn’t clear enough but I want to see the .times method in Swift for my own usage, not for beginners. :)</div><div><div class="h5"><br><blockquote type="cite"><div><div style="word-wrap:break-word"><div>
<br><div><blockquote type="cite"><div>Le 18 déc. 2015 à 13:38:59, Cihat Gündüz via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> a écrit :</div><br><div><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">I agree with both of you about the alternative implementations.</span><div style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><br></div><div style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px">That’s exactly what I’d love to see integrated to the standard library like Ruby is here:<div><a href="http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times" target="_blank">http://ruby-doc.org/core-2.2.4/Integer.html#method-i-times</a></div><div><br></div><div>My main problem is that it neither looks<span> </span><b>clean</b><span> </span>nor<span> </span><b>readable</b><span> </span>especially for beginners that there is an<span> </span><i>underscore</i><span> </span>in the closure. Also beginners often get confused with the number of times some code is run when<span> </span><i>starting to count from 0</i><span> </span>which is also why I think it shouldn’t appear. The .times method would solve both of these problems.</div><div><br><div><blockquote type="cite"><div>Am 18.12.2015 um 19:33 schrieb Etan Kissling <<a href="mailto:kissling@oberon.ch" target="_blank">kissling@oberon.ch</a>>:</div><br><div><div style="word-wrap:break-word">(or with a for in loop -- but i guess you have a reason for using .foreach)<div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">for</span><span> </span><span style="color:rgb(187,44,162)">_</span><span> </span><span style="color:rgb(187,44,162)">in</span><span> </span><span style="color:rgb(39,42,216)">0</span>..<<span style="color:rgb(39,42,216)">5_000</span><span> </span>{</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(61,29,129)">print</span>(<span style="color:rgb(209,47,27)">"asdf"</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div><br></div><div><br></div><div><blockquote type="cite"><div>On 18 Dec 2015, at 19:31, Etan Kissling via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word"><div>You don't need stride for this.</div><div><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">func</span><span> </span>foo() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> (<span style="color:rgb(39,42,216)">0</span>..<<span style="color:rgb(39,42,216)">5_000</span>).<span style="color:rgb(61,29,129)">forEach</span><span> </span>{<span> </span><span style="color:rgb(187,44,162)">_</span><span> </span><span style="color:rgb(187,44,162)">in</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(61,29,129)">print</span>(<span style="color:rgb(209,47,27)">"asdf"</span>)</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div></div><div><br></div><br><div><blockquote type="cite"><div>On 18 Dec 2015, at 19:25, Cihat Gündüz via swift-evolution <<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>> wrote:</div><br><div><div style="word-wrap:break-word">Dear Swift-Community,<div><br></div><div>I’d like to propose an<span> </span><b>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><br></div><div>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><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(187,44,162)">func</span><span> </span>testPerfQualityInPercentWithoutQualityImprovements() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span> <span> </span></span><span style="color:rgb(187,44,162)">self</span><span>.</span>measureBlock<span><span> </span>{</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(187,44,162)">let</span><span> </span>expectedQuality =<span> </span><span style="color:rgb(39,42,216)">33.33</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(39,42,216)">0</span>.<span style="color:rgb(61,29,129)">stride</span>(to:<span> </span><span style="color:rgb(39,42,216)">5_000</span>, by:<span> </span><span style="color:rgb(39,42,216)">1</span>).<span style="color:rgb(61,29,129)">forEach </span>{<span> </span><span style="color:rgb(187,44,162)">_</span><span> </span><span style="color:rgb(187,44,162)">in</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span> </span><span style="color:rgb(49,89,93)">XCTAssertEqualWithAccuracy</span>(<span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(79,129,135)">crossword</span>.<span style="color:rgb(79,129,135)">qualityInPercent</span>, expectedQuality, accuracy:<span> </span><span style="color:rgb(39,42,216)">0.1</span>) </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> } </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div></div><div><br></div><div>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><br></div><div>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><br></div><div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">func</span> testPerfQualityInPercentWithoutQualityImprovements() {</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(49,89,93)"><span> </span><span style="color:rgb(187,44,162)">self</span><span>.</span>measureBlock<span> {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(187,44,162)">let</span> expectedQuality = <span style="color:rgb(39,42,216)">33.33</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(39,42,216)">5_000.times {</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> <span style="color:rgb(49,89,93)">XCTAssertEqualWithAccuracy</span>(<span style="color:rgb(187,44,162)">self</span>.<span style="color:rgb(79,129,135)">crossword</span>.<span style="color:rgb(79,129,135)">qualityInPercent</span>, expectedQuality, accuracy: <span style="color:rgb(39,42,216)">0.1</span>) </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> } </div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"> }</div></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"><span 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 style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px">I wish you all the best,</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px">Cihat</span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px"><br></span></div><div style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span style="font-family:Helvetica;font-size:12px"><br></span></div><div 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 style="margin:0px;line-height:normal"><br></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" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"></div>_______________________________________________<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></div></blockquote></div><br><img src="https://u2002410.ct.sendgrid.net/wf/open?upn=tTTJ5sn5y0uc3ODSZa-2BndLNwXCDS7T2cq5OlDDhG0Rudyoy59P95VIFCXE8vsNIm3CRv2xeSfRQi24G3J7csJAwXsAU0KgdqyUmTpkPgjbX8d25r2mfuva9tzq-2FUDdol4HlpIh-2BHPdrv3VJ3o4xk2ghsZ6aTSUz-2FXhHLeKnEcHzsL3XLw-2F2NTNaky7syxtgWh87TGLUN5goHMjwNXVFxk5QMxUtPLGjvJKyN7d4juEc-3D" alt="" width="1" height="1" border="0" style="min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"></div>_______________________________________________<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></div></blockquote></div><br></div></div></div></blockquote></div><br></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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;min-height:1px!important;width:1px!important;border-width:0px!important;margin:0px!important;padding:0px!important"><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important"><span> </span></span><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">_______________________________________________</span><br style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><span style="font-family:LucidaGrande;font-size:12px;font-style:normal;font-variant:normal;font-weight:normal;letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;float:none;display:inline!important">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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px"><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;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a></div></blockquote></div><br></div></div></div></blockquote></div></div></div><br>
<img src="https://u2002410.ct.sendgrid.net/wf/open?upn=P-2BsYbBZHRBuLDBJaL4DIKDNfkkjpROowTyRAObV11qz30h3cpkMMxhivEnrd0XfrbYGIeY1enyDmgOsAs-2B0eo2fnrzNXqVVFe1DvcBbmaIr0Y7tsJfMylPSDLFumCJDxjA-2Bk2RpYVv92dgUbgmknSgJmYLx5ZtpN-2B-2Blzvqj6Cw0IrboApkpaYbFgP7Oe1cIYQY5XLDjSms6Z3XTqiVaBA8HLoP8IFe8xWRoLGytHAok-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>
<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>