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

Xiaodi Wu xiaodi.wu at gmail.com
Fri Jun 10 22:23:22 CDT 2016

On Fri, Jun 10, 2016 at 9:25 PM, Jonathan Hull <jhull at gbis.com> wrote:

> Please leave this feature in!
> One of the places I get bitten the most during refactoring is somehow
> missing a ‘continue’ statement inside the loop (and I hear that is a common
> issue).  For-in-where lets me guard against that problem in simple cases.

Hmm, that's an interesting use case. That said, the simple case that could
get replaced by `where` is an opening `guard` statement, precisely one that
you wouldn't somehow miss. The ones you'll get bitten by, you'll still get
bitten by whatever way this goes...

> I also find that it is often the clearest way to capture the semantics of
> what I want.  I find it extremely readable and compact. Everything is all
> in one place :-)
> As for the issue of “dialects”, it really just feels like people are
> trying to force their particular pet coding style on everyone else.

Not at all (at least not from me). We find `while` to be problematic for
the reasons outlined in the draft proposal, not for reasons of style. On
the contrary, it's the advocates for keeping `while` that argue that it's
good style. (Which I dispute, but which is not the reason for the proposal.)

> Should we get rid of .forEach() as well?  Sometimes languages have more
> than one way to do something, and it is up to the programmer to pick the
> form that is clearest in the context of use...
> Thanks,
> Jon
> I respect that anti-goal, but I think being over-rigid about limiting
> developers' choice of expression is also an anti-goal.
> To me, it is like guard statements vs. if-let statements. Some people find
> one to be more clear than the other. Often times the best choice depends on
> the context. Sometimes a guard statement can be re-written as an if-let
> statement in a way that makes the code more clear, and vice versa. And
> different people will inevitably have different personal preferences -
> their own "style", if you will - and will favor one over the other. But it
> would be a mistake to force everyone into one box in order to prevent the
> fracturing of the Swift community into "dialects."
> But most importantly (and this is really the kicker for me) there are times
> when the "where" syntax provides the maximum amount of clarity in the
> context of my code, and I don't want to lose that expressive power.
> On Fri, Jun 10, 2016 at 10:17 AM Xiaodi Wu <xiaodi.wu at gmail.com <https://lists.swift.org/mailman/listinfo/swift-evolution>> wrote:
> >* I think this idea--if you don't like it, then you don't have to use it--is
> *>* indicative of a key worry here: it's inessential to the language and
> *>* promotes dialects wherein certain people use it and others wherein they
> *>* don't. This is an anti-goal.*
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160610/1c2d8180/attachment.html>

More information about the swift-evolution mailing list