[swift-evolution] [Pitch] Retiring `where` from for-in loops
Xiaodi Wu
xiaodi.wu at gmail.com
Mon Jun 13 12:33:19 CDT 2016
On Mon, Jun 13, 2016 at 12:24 PM, Haravikk <swift-evolution at haravikk.me>
wrote:
>
> > On 13 Jun 2016, at 13:28, Xiaodi Wu via swift-evolution <
> swift-evolution at swift.org> wrote:
> >
> > I think this discussion has made it pretty plain that what is claimed to
> be 'so useful' is barely ever used. Moreover, it provides no independent
> uses. The point of these pitches is to sound out arguments, not, as far as
> I was aware, to take a vote.
>
> I think that the discussion has made it clear that far more people want
> this feature to remain, and feel it is a valid part of the language,
> whether or not it’s a mainly aesthetic one, and that it should stay.
> Whether or not the discussion is intended as a vote is irrelevant, if more
> people want a feature to remain than want it removed then that suggests the
> justification for removing it had better be a really good one.
>
> So far we have redundancy, which isn’t really sufficient reason to remove
> something, as we have plenty of redundant syntax for convenience. Take
> conditional binding for example, which is essentially just a shorthand for
> pattern matching. Functionally they’re identical, and there’s not much
> difference in complexity (you don’t have to learn the pattern matching
> aspect in order to use it for unwrapping optionals), so really it’s just a
> neat shorthand similar to where, and could be removed easily, yet people
> would fight against it just as furiously.
>
> Otherwise the argument is against confusion/mistakes, but this alone isn’t
> a reason to remove a feature vs addressing why confusion is caused.
> Besides, the main argument for it being confusing comes from its use in
> both while and for loops, but if it’s being removed from while loops then
> this ceases to be an issue. As a result it would be premature to remove the
> feature as we don’t know yet if it’s still confusing when only permitted on
> for loops.
>
> After that the other issue is whether filtering deserves a special case,
> but this is muddied by a lack of use largely resulting from lack of
> awareness. For us to get useful evidence either way would require this to
> put more widely known and to see if it continues to be used infrequently; I
> know about the keyword and use it in maybe 20% of my for loops (plus I
> actually rarely use while loops, and mainly in testing).
> Besides which there is a proposal for a variant of where (while/until)
> which gives access to another fairly common variant of if/guard that
> developers may wish to replace, which would address a lack of versatility.
>
> The benefit of the where clause is eliminating a line by putting the same
> condition on the opening loop, you may not consider this worthwhile but
> clearly plenty of people do,
It's not that I don't consider it worthwhile. I consider it *harmful*
because it leaves implicit the key question of what happens when `where` is
not fulfilled.
> therefore I’d consider this justification enough for the feature to remain
> as we find it useful and prefer how our code looks with this shorthand. You
> remain free as ever to not use it.
Otherwise, I think you sum up the arguments that have been laid out pretty
well. All in all, I believe we've made a case that's stronger than the one
that was made for the for;; loop. At this point, I think there's little
left to discuss prior to a formal review.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160613/860e6f2f/attachment.html>
More information about the swift-evolution
mailing list