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

Xiaodi Wu xiaodi.wu at gmail.com
Wed Jun 15 17:34:09 CDT 2016


On Wed, Jun 15, 2016 at 4:58 PM, Dany St-Amant via swift-evolution <
swift-evolution at swift.org> wrote:

>
> > Le 15 juin 2016 à 17:23, Jean-Daniel Dupas via swift-evolution <
> swift-evolution at swift.org> a écrit :
> >
> >
> >> Le 13 juin 2016 à 17:26, Erica Sadun via swift-evolution <
> swift-evolution at swift.org> a écrit :
> >>
> >>
> >>> On Jun 13, 2016, at 9:23 AM, let var go via swift-evolution <
> swift-evolution at swift.org> wrote:
> >>>
> >>> I am 100% with Charlie on this. Expressiveness has to do with the
> *effectiveness* of conveying a thought or a feeling.
> >>>
> >>> Keep "where". It is expressive. It conveys a specific idea effectively
> and concisely.
> >>
> >> For those of you in favor of retaining `where`, how do you feel about
> adding `while`, `until`, `unless`, etc?
> >>
> >> — E
> >
> > What I like is the possibility to iterate over a filtered list using a
> ‘single’ statement, not the keyword itself. If you propose to replace where
> by something less confusing, or add other keywords, I’m all for it.
> >
>
> For the folks who like the 'where' and do not like the 'guard .. else
> continue', (also considering in the equation the suggestion of renaming
> 'where' by 'if'). One can get the 'where' syntax without the 'where'  at
> the cost of one indentation level and the set of curly braces.
>
> for element in dataArray {
>   if condition {
>     doWork()
>   }
> }
>
> versus
>
> for element in dataArray where condition {
>   doWork()
> }
>

...and (not that I would advocate for this as the best style), you could
simulate the keyword with a slightly funny indentation:

```
for element in dataArray { if condition {
  doWork()
}}
```

(...and if we're counting letters typed as a metric for terseness, not that
I would advocate that metric, `where` and `if {}` are both exactly five...)


> Dany, slowly shifting into the "what's the point of keeping 'where'" camp
>

:)


> _______________________________________________
> swift-evolution mailing list
> swift-evolution at swift.org
> https://lists.swift.org/mailman/listinfo/swift-evolution
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160615/5b2ae8d7/attachment.html>


More information about the swift-evolution mailing list