[swift-evolution] [Pitch] Retiring `where` from for-in loops

Erica Sadun erica at ericasadun.com
Fri Jun 10 10:49:43 CDT 2016


> On Jun 10, 2016, at 9:24 AM, Erica Sadun <erica at ericasadun.com> wrote:
> 
> 
>> On Jun 10, 2016, at 9:22 AM, Erica Sadun via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>> 
>> 
>>> On Jun 10, 2016, at 8:02 AM, Xiaodi Wu via swift-evolution <swift-evolution at swift.org <mailto:swift-evolution at swift.org>> wrote:
>>> 
>>> On Fri, Jun 10, 2016 at 7:18 AM, Haravikk <swift-evolution at haravikk.me <mailto:swift-evolution at haravikk.me>> wrote:
>>>> * The word "where" does not consistently imply `break` or `continue`. In current Swift, `where` implies `break` in the context of a `while` loop and `continue` in the context of a `for` loop. Some users intuitively guess the correct meaning in each context, while others guess the wrong meaning. Therefore, the only way to learn for sure what `where` means in any context is to read the rulebook. That, by definition, means that this is unintuitive.
>>> 
>>> This is an argument for renaming the where keyword on for loops to be more clear, or to somehow integrate continue/break to be more explicit about what the developer intends for it to do.
>>> 
>>> Sure: I conclude that the keyword should be *either* removed *or* reformed; both outcomes could address the issue.
>> 
>> This is my stance as well and I reserve the right to flit between both choices until we've fully talked it through.
>> 
>> One more data point. 
>> 
>> In the standard library there are just under 950 uses of "for in loops". There are 3 uses of "for in while" :
>> 
>> private/StdlibUnittest/StdlibUnittest.swift.gyb:    for j in instances.indices where i != j {
>> public/core/Algorithm.swift:  for value in rest where value < minValue {
>> public/core/Algorithm.swift:  for value in rest where value >= maxValue {
>> 
>> -- Erica
> 
> Actually a slight correction to that. I forgot to add the space after "in" on the first search. It's just over 600 and 3. Among the 600 are a few false positives but not many.
> 
> -- E

And to follow-up to myself once again, I went to my "Cool 3rd Party Swift Repos" folder and did the same search. Among the 15 repos in that folder, a joint search returned about 650 hits on for-in (again with some false positives) and not a single for-in-while use.

-- E
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/d2082d54/attachment.html>


More information about the swift-evolution mailing list