[swift-evolution] [Pitch] Retiring `where` from for-in loops
Vladimir.S
svabox at gmail.com
Tue Jun 14 08:04:38 CDT 2016
On 13.06.2016 18:59, L. Mihalkovic via swift-evolution wrote:
>>>> I don’t dispute that we *could* live without “where” - that is not
>>>> the point. We could also live without classes or generics or any
>>>> of a variety of other features - but why should we when we don’t
>>>> have to?
> The corollary question every parent has to deal with is to learn to make
> a sacrifice now for a better outcome tomorrow. Maybe this is another way
> to look at this question?
>
Yes, if you know *for sure* it it will be "better outcome" tomorrow. I.e.
we even don't have any thoughts about what LINQ for Swift can look like,
and when we'll only start to discuss this(4.x? 5.x? 6.x?), but we
definitely needs to remove handful feature now and then keep the hope it
will return in more powerful way. Probably we need to be very close to
situation when 'where' in 'for-in' loop prevents introduction of LINQ-like
feature to remote this 'where'? (probably with for-in loop together).
Again, we have sugar of `for-in` to be able to iterate
sequences&collections in handy way, we need it only for this purpose. We
have 'where' feature in 'for-in' to be able to filter the iterating
sequence. Filtering is essential operation for sequences/collections
(.filter is one of main 3 operations : filter/map/reduce). As we have a
special sugar to iterate sequences I find it very logical to have in it a
sugar to filter iterated sequences. Force people to use guard-continue
instead of 'where' for me is equal to force to use 'while' loop to iterate
sequences instead of `for-in` loop.
Also, as was mentioned, in some situations you want to apply logically
'main' filter in 'where' clause and then use guard-continue for additional
filters/checks in body.
And 'where' in for-in loops does exist now in Swift. IMO you need really
strong arguments to remove it. I've read all the messages of Xiaodi and
Erica(and others), and I didn't find any argument that clearly shows that
'where' is a bad thing and must be removed, I saw your opinions or your
view of Swift future or your understanding of Swift goals or your
understanding of core-team thoughts or your preferable style for coding etc.
If it is not clear if 'where' has 'continue if fails' behavior - IMO we
need to *rename* it. It is just not logically to remove the feature if
keyword is not clear enough(*for some beginners who see it the first time)
- make the keyword clear, then you have no main argument to remove the
_feature_.
More information about the swift-evolution
mailing list