<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Mon, Jun 13, 2016 at 9:27 AM, Vladimir.S <span dir="ltr"><<a href="mailto:svabox@gmail.com" target="_blank">svabox@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">IMO `for-in` is a special kind of loop to manipulate(iterate) a collection, and was introduced because we so *often* needs to iterate collections that we need a *sugar* for this (you can do all the same with `while` loop).<br></blockquote><div><br></div><div>Sequences, not just collections.</div><div><br></div><div>It's rather tricky to write a `while` loop *correctly* to do the same thing as a `for` loop, and it exposes the concept of the underlying iterator, which is a more advanced concept. This is why the `for...in` loop hold its own weight as sugar. By contrast, `while` does not, because it is trivial to write an `if` or `guard` statement correctly, and mastering the concept of a conditional statement is a prerequisite for mastering loops. For these reasons, it's not apt to compare `while` clauses with `for...in` loops.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
*Filtering* is another important operation we often need during the iteration of collection.</blockquote><div><br></div><div>I think the evidence has shown that it's actually not very often that you need to do so.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">This is why many of us want to keep `where` for `for-in` loop. Yes, as sugar, because it really simplifies our every day coding(processing of collections) and makes the code more readable(IMO) and understandable(IMO).<br></blockquote><div><br></div><div>FWIW, IMO, it's less readable and less understandable. But there's no point in going back and forth on this.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Personally I don't insist on `where` keyword, probably we can find another word, so it will not be mixed with `where` in other places of the language.<br>
<br>
Why not `filter` instead of `where` ?<br>
<br>
for item in collection filter item < 10 {..}<br>
<br>
we have .filter for collections, it is clear what it means, `filter` in `for-in` mimics the same behavior, etc<br>
<br>
I'd even suggest to make `for-in` loop more powerful with adding suggested 'while' but as under another name. So, `for-in` will be a powerful construct to iterate, filter and break processing of collections - the only one purpose why we need `for-in` at all.<br></blockquote><div><br></div><div>We already have keywords for breaking and for prematurely terminating from a loop. They're called `break` and `continue`, and they work inside every loop.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
for item in collection until item > 100 {..}<br>
or<br>
for item in collection break item > 100 {..}<br>
or<br>
for item in collection breakif item > 100 {..}<br>
or<br>
for item in collection limit item > 100 {..}<br>
or<br>
for item in collection stop item > 100 {..}<br>
or other keyword.<span class=""><br>
<br>
<br>
On 13.06.2016 16:36, Xiaodi Wu via swift-evolution wrote:<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
On Mon, Jun 13, 2016 at 8:16 AM, Brandon Knope <<a href="mailto:bknope@me.com" target="_blank">bknope@me.com</a><br></span><div><div class="h5">
<mailto:<a href="mailto:bknope@me.com" target="_blank">bknope@me.com</a>>> wrote:<br>
<br>
Are you really surprised that some people don't want this taken away?<br>
<br>
<br>
Nope, that's to be expected.<br>
<br>
<br>
The burden should be on those that want it taken out of the language<br>
and not those that want it kept. After all something is being removed<br>
and it should be a delicate process.<br>
<br>
<br>
Agreed. We who think it's better to take this syntax out have advanced an<br>
argument with several prongs. Namely, that the `where` clause serves no<br>
independent purpose; that a more general solution has already been added to<br>
the language (as well as another in the stdlib); that the `where` clause is<br>
not necessary for progressive disclosure to new users before they're ready<br>
for the general solution; that it is, at present, rarely used in practice;<br>
that it has no analog in other commonly used general purpose languages in<br>
the C family; that it is the remnant of a direction in which the core team<br>
later decided not to pursue; and that, given its lack of utility, lack of<br>
use, and vestigial state, being the cause of confusion even among a small<br>
number of users (if their number be small) is grounds to conclude that it<br>
is harmful to the language and therefore ought to be removed.<br>
<br>
<br>
Don't be surprised when the defenders say it is more readable to them.<br>
That is a *sound* argument in my opinion.<br>
<br>
<br>
IMO, it cannot stand on its own as a complete argument for saving a feature<br>
in the face of the arguments we've advanced. Couldn't you say the same for<br>
`++` or `for;;` loops? I'd say our case is at least as strong as that for<br>
`for;;` loops. By comparison, if I recall, the `for;;` loop was argued to<br>
be ill-fitting the rest of the language and lacking in usage, but it<br>
certainly had utility independent of `for...in` loops and was well<br>
precedented in C languages.<br>
<br>
<br>
<br>
Brandon<br>
<br>
Sent from my iPad<br>
<br>
On Jun 13, 2016, at 8:33 AM, Xiaodi Wu via swift-evolution<br></div></div>
<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> wrote:<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
This is not a sound argument. If your filtering can be expressed as a<br>
where clause, then you would only have to read one line into the loop<br>
to see it in the form of a guard clause.<br>
<br>
Moreover, if what you're arguing is that you shouldn't ever have to<br>
*read* inside the loop to know if a sequence is filtered, how do you<br>
propose that we do that? Remove the continue keyword?<br>
<br>
On Mon, Jun 13, 2016 at 6:16 AM Jean-Daniel Dupas via swift-evolution<br></span><span class="">
<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> wrote:<br>
<br>
-1 for the removal.<br>
<br>
When I read code, I find it far more visible that a loop is over<br>
a filter list when the filter clause is on the same line, than<br>
when the filter clause is inside the loop.<br>
<br>
Having to read the full content of the loop to determine if the<br>
list is filtered or not is not an improvement IMHO.<br>
<br>
Moreover, I find it far cleaner to use the where clause that<br>
having to remember than I have to use the lazy accessor to avoid<br>
a performance hit.<br>
<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">
Le 13 juin 2016 à 06:39, Charlie Monroe via swift-evolution<br></span>
<<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>>> a<span class=""><br>
écrit :<br>
<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
And to follow-up to myself once again, I went to my "Cool 3rd<br>
Party Swift Repos" folder and did the same search. Among the 15<br>
repos in that folder, a joint search returned about 650 hits on<br>
for-in (again with some false positives) and not a single<br>
for-in-while use.<br>
<br>
-- E<br>
</blockquote>
<br>
Not to undermine this fact, but I believe the fact that `where`<br>
can be used in a for loop is not widely known. I didn't know<br>
about it until about a month ago (haven't really read much docs,<br>
but most people don't either).<br>
<br>
But after I found out about it, I started using it and it IMHO<br>
improved readability of my code. Not by much, but it's the<br>
little things that make you smile, right?<br>
<br>
Many people here argument that `where` is a Swift speciality and<br>
needs to be learned by the developer - the alternative is to<br>
teach the person what's the proper alternative - that using<br>
.filter can have performance impact and that the *correct* way<br>
is to use guard within the for loop. And that's IMHO much worse<br>
than teaching a person about using `where` within a for loop.<br>
<br>
</span><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote>
<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>><span class=""><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>
_______________________________________________<br>
swift-evolution mailing list<br></span>
<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a> <mailto:<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</blockquote><span class="">
<br>
<br>
<br>
<br>
_______________________________________________<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" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
<br>
</span></blockquote>
</blockquote></div><br></div></div>