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

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_.

Ā·Ā·Ā·

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?

I was not advocating the lack of constraints, programmers like all other
artists (and engineers, which are artists too ;)), but that the beauty is
the moderation of the two extremes :). ... and that architects leave the
problems you are talking about to the structural engineer :P.

Gravity is a constrain, but a different one than having to use only a
certain pencil to do your sketches with and only being able to use Windows
95 OSR 3 to work on or even weirder limitations.

Ā·Ā·Ā·

On Fri, Jun 10, 2016 at 7:59 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Fri, Jun 10, 2016 at 1:11 PM, Goffredo Marocchi <panajev@gmail.com> > wrote:

I think sometimes the community in this mailing list loses sight on the
fact that coding is a creative endeavour much similar to architectural
design or painting. There may be math and well researched and structured
ideas in place, but it requires creativity too.

Architects are constrained to craft buildings that will stand in the face
of gravity, and even painters don't have pigments for every color visible
to the human eye. There's a wonderful novel, _Gadsby_, written without the
letter 'e'; I haven't read it but I understand it's truly an
accomplishment. This is not so drastic here. In this case, the apt analogy
would be that we find the letter 'a with circle on top' to be posing some
pesky problems; do you think you could write a novel in English without
using 'a with circle on top'? I wager that your creativity will not suffer
(unless your novel describes a trip to IKEA, in which case I'm sorry).

Trying to force a strict one size fits all The One True standard usually
ends up fragmenting the standard further, by adding yet another take on
what is the most orthodox implementation and who are the heretics...

I do not think dismissing the idea of having more than one way of
skinning the proverbial cat as an anti-goal is doing a good service to the
community or the language as it completely disregards context, people
differing idea of the subjective best coding style and patterns (which
pattern do I use? Which algorithm do I use to sort this data set with? A
good engineer will give you a direct and concise answer, but a better one
will say "it depends... What's the context? What is the problem I need to
solve, what are the constraints and the data set I am working on?").

The way some users seem to want Swift to follow sounds like protecting
users from mistakes by sometimes removing the ability which could lead to
mistakes in the first place, but that removes all the good things you could
do if you were to trust developers with the extra responsibility.

Sent from my iPhone

On 10 Jun 2016, at 18:30, let var go via swift-evolution < >> swift-evolution@swift.org> wrote:

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@gmail.com> 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.

On Fri, Jun 10, 2016 at 12:10 let var go <letvargo@gmail.com> wrote:

Leave it in!

It's a great little tool. I don't use it very often, but when I do it
is because I've decided that in the context of that piece of code it does
exactly what I want it to do with the maximum amount of clarity.

If you don't like it, then don't use it, but I can't see how it
detracts from the language at all.

The *only* argument that I have heard for removing it is that some
people don't immediately intuit how to use it. I didn't have any trouble
with it at all. It follows one of the most basic programming patterns ever:
"For all x in X, if predicate P is true, do something." The use of the
keyword "where" makes perfect sense in that context, and when I read it out
loud, it sounds natural: "For all x in X where P, do something." That is an
elegant, succinct, and clear way of stating exactly what I want my program
to do.

I don't doubt that it has caused some confusion for some people, but
I'm not sold that that is a good enough reason to get rid of it. It seems
strange to get rid of a tool because not everyone understands how to use it
immediately, without ever having to ask a single question. As long as its
not a dangerous tool (and it isn't), then keep it in the workshop for those
times when it comes in handy. And even if there is some initial confusion,
it doesn't sound like it lasted that long. It's more like, "Does this work
like X, or does this work like Y? Let's see...oh, it works like X. Ok."
That's the entire learning curve...about 5 seconds of curiosity followed by
the blissful feeling of resolution.

On Fri, Jun 10, 2016 at 9:32 AM Xiaodi Wu via swift-evolution < >>>> swift-evolution@swift.org> wrote:

On Fri, Jun 10, 2016 at 11:23 AM, Sean Heber via swift-evolution < >>>>> swift-evolution@swift.org> wrote:

> 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.

Weird. My own Swift projects (not on Github :P) use ā€œwhereā€ all the
time with for loops. I really like it and think it reads *and* writes far
better as well as makes for nicer one-liners. In one project, by rough
count, I have about 20 that use ā€œwhereā€ vs. 40 in that same project not
using ā€œwhereā€.

In another smaller test project, there are only 10 for loops, but
even so one still managed to use where.

Not a lot of data without looking at even more projects, I admit, but
this seems to suggest that the usage of ā€œwhereā€ is going to be very
developer-dependent. Perhaps there’s some factor of prior background at
work here? (I’ve done a lot of SQL in another life, for example.)

That is worrying if true, because it suggests that it's enabling
'dialects' of Swift, an explicit anti-goal of the language.

I feel like ā€œwhereā€ is a more declarative construct and that we
should be encouraging that way of thinking in general. When using it, it
feels like ā€œmagicā€ for some reason - even though there’s nothing special
about it. It feels like I’ve made the language work *for me* a little bit
rather than me having to contort my solution to the will of the language.
This may be highly subjective.

l8r
Sean

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

-1

* Swift is explicitly a C-family language. In most or all other C-family languages, for loop statements allow specification of conditions for exiting the loop but not for filtering. Therefore, Swift's use of `where` is unprecedented and needs to be learned anew by every user of Swift.

When was this decided? I distinctly remember some bloke under Craig Federighi’s hair saying that it was time to ā€œmove beyondā€ C and essentially ditch legacy conventions which no longer make sense.

I think you misunderstood my argument here. I don't mean that we should yoke ourselves to C conventions, and we should absolutely ditch C convention when it doesn't make sense. The big-picture argument here is that `where` doesn't pass the bar of correcting a C convention that no longer makes sense.

FWIW, on the topic of syntax choices, here is what Chris Lattner had to say on this list:

Kevin got it exactly right, but I’d expand that last bit a bit to:
ā€œā€¦ picking the one that is most familiar to programmers in the extended C family is a good idea.["]
The extended C family of language (which includes C, C++, ObjC, but also C#, Java, Javascript, and more) is
an extremely popular and widely used set of languages that have a lot of surface-level similarity. I
don’t claim to know the design rationale of all of these languages, but I surmise that this is not an
accident: programmers move around and work in different languages, and this allows a non-expert in the
language to understand what is going on. While there are things about C that are really unfortunate IMO
(e.g. the declarator/declaration specifier part of the grammar) there is a lot of goodness in the basic
operator set, focus on dot syntax, and more.
I do agree that there are some benefits to ditching braces and relying on indentation instead, but there are
also downsides. Deviating from the C family in this respect would have to provide *overwhelmingly* large
advantages for us to take such a plunge, and they simply don’t exist.

As I understand it, Swift is a new language with new conventions. It is desirable to align as many of those as possible with existing conventions so as to be easily learned, but if you limit Swift to other languages conventions you deny it any identity. Did Python ask anybody’s opinion before dropping curly-braces? Did people learn whatever Perl is supposed to be? Look at C’s hieroglyphic for loops!

I don't think we disagree here.

Realistically, ā€œfor … in … whileā€ is not going to cause incredible confusion. Removing it would cause a lot of frustration. You can’t on the one hand say our users are comfortable with the axioms of C’s hieroglyphic loops, and on the other hand say ā€œfor x in y while" is confusing.

Again, as I said, once you've mastered something, by definition you find it not confusing. Why should we doom x% of new users to writing a loop incorrectly at least once when we don't have to?

Ah, but if you’re not ā€œdoomedā€ to failing once, how will you ever master anything? Nobody knew how to write a C for-loop until someone showed them (and even then…). Nobody is going to just open a REPL and start writing code, with zero prior understanding of what Swift syntax looks like.

The thought here is along the lines of what Chris said, quoted above, and repeated here: "The extended C family of language [...] is an extremely popular and widely used set[;] programmers move around and work in different languages, and [aligning to expectations arising from other C family languages] allows a non-expert in the language to understand what is going on." By contrast, the `where` clause violates that expectation and I do not see "overwhelmingly large advantages" for doing so.

What about C#'s `where` then? As C# is a member of the C family languages `where` is not violating expectations!

Where is not exactly a part of c# it belongs to linq

And that is not a part of C#??

SQL is a domain-specific language, and LINQ is an internal domain-specific language with a language extension for C#. Neither is a general purpose language.

Your example actually goes to one of Laurent's points. Should the Swift core team or an enterprising community member propose a set of similarly powerful tools, along with a set of language extensions that add syntactic sugar for them, I (and I think Laurent, if I understand him correctly) would absolutely be in favor of such an addition. But as it is, `where` is an odd duckling. Just as you say, it looks like a component of a query language, but it does no such thing. In a for loop, it does some filtering, but until recently it functioned like a comma in `while` loops. Look at those other keywords which make this sugar possible in C#: in your example, `from` and `select`. We don't have any of that intrastructure in Swift.

IMHO the team has taken an Ockham Axe to the grammar: in the presence of multiple ways to produce the same or an acceptable stand-in (for eg when the only difference is an acceptable temporary perf setback), then the solution requiring the least assumptions on the compiler wins.

I would even extend this rule with the corollary that between an assumption materialized as a type checker rule and an assumption materialized as a full blown extra language keyword, there might be a bias to accept the former if it kills the latter. But this is just my personal inference of what their decision heuristic might be based solely on what I saw. My sole interest in trying to understand their decision making process is to try to avoid proposals that have little to no chance to go anywhere, as well as trying to present ones that will align better with where the language is going.

In this instance, WHERE is a heavy assumption on the compiler for no greater gain than filters can provide. So I think we save the WHERE keyword for an outcome that will be really worth it! Something along the idea of Linq, but with a proper Swift feel to it. What does it look like? I cannot say yet. But the good news is that having taken WHERE out now will make that next step a purely additive process (nothing will be taken out then, but a big thing will be gained).

I am all for extending `for` to be more like Scala’s `for`-expression or Haskell’s `do`-notation. LINQ might be too focused on querying.
Extending the current `where` to be syntax sugar for `filter` would be quite straightforward, though, so I’m not sure whether removing it first is really necessary.
That was not object of the pitch to retire `where` from `for`-loops, though. Instead the argument was (and still is) that `where` might be misunderstood there by beginners and should therefore be removed. This argument would apply to an extended `where` unchanged, because I can still write the exact same code as being criticized now and can even do more complicated things which would by even more hard to understand for beginners.
That’s the argument I disagree with.

The following is an example from MSDN with `where` clearly beaing a keyword:

var numQuery = from num in numbers where (num % 2) == 0 select num;

Here is food for your thoughts, you think WHERE is a keyword?! then look at this:

var numbers = new int{0,1,23,4,5,6,7,87,9};
var numQuery = from num in numbers where (num % 2) == 0 select num;

Program does not compile:

// Error CS1935: An implementation of `Where' query expression pattern could not be found. Are you missing `System.Linq' using directive or `System.Core.dll' assembly reference? (CS1935) (SessionsFinder)

using System.Linq;
var numbers = new int{0,1,23,4,5,6,7,87,9};
var numQuery = from num in numbers where (num % 2) == 0 select num;

That program does compiles and runs fine. This tells you that ā€œwhere" is not at all the ordinary keyword that it appears to be. hence my ā€œit is not C# per-se, it is Linqā€.

Digging into C# Features That Support LINQ - C# | Microsoft Learn and C# Keywords - C# | Microsoft Learn tells me the following:
(1) `from`, `where` etc. are contextual keywords, but they are nonetheless keywords of C# and expressly *not* a specific feature of LINQ: "Although these new features are all used to a degree with LINQ queries, they are not limited to LINQ and can be used in any context where you find them useful."
(2) the compiler translates them into standard method calls (like Scala’s `for`-expression or Haskell’s `do`-notation). That is an integral part of C#.
(3) your error message originates from not having an implementation of a `Where`-method in scope. You could have provided one yourself instead of `using System.Linq`.

Of course the compiler knows about it... My exact wording was "ordinary keyword" implying, "it is one, just not in the sense you are giving it right now". Knowing you would want to dig further I had to find a description that was true albeit leaving the fine details out (i doubt too may actually care about the distinction between contextual and non-contextual kwd, or the fact that sql is turing complete ;) ).

My thought is to accept the downgrading from its current status because its complete behavior is limited and hetched in blood inside the grammar, therefore not extensible without grammar alterations; thereby leaving the door open for a future re-introduction ala-Linq in v4+. I use the term "ala-linq" as a placeholder for "some sort of more dynamic behavior resulting from a close collaboration between compiler, stdlib, runtime and user code". And i still believe nobody outside doug, joe, chris, or jordan cares about the actual implementation details.

Again, this is just a personal view on what looks IMHO like a great opportunity.

Ā·Ā·Ā·

On Jun 12, 2016, at 3:21 PM, Thorsten Seitz <tseitz42@icloud.com> wrote:

Am 12.06.2016 um 12:02 schrieb L Mihalkovic <laurent.mihalkovic@gmail.com>:
On Jun 11, 2016, at 11:45 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:
On Sat, Jun 11, 2016 at 3:37 PM, Thorsten Seitz <tseitz42@icloud.com> wrote:

Am 11.06.2016 um 22:29 schrieb L. Mihalkovic <laurent.mihalkovic@gmail.com>:

On Jun 11, 2016, at 9:53 PM, Thorsten Seitz via swift-evolution <swift-evolution@swift.org> wrote:

Am 10.06.2016 um 18:28 schrieb Xiaodi Wu via swift-evolution <swift-evolution@swift.org>:

On Fri, Jun 10, 2016 at 6:10 AM, Karl <razielim@gmail.com> wrote:

And if you still wonder, then rewrite the code so that ā€œWHEREā€ no longer looks like a keyword:

var numQuery2 = numbers.Where( num => num %2 == 0); // exact same result as numQuery1

That’s exactly what I expected as it is the standard way syntactic language sugar is mapped to customizable behavior. Haskell’s `do`-notation or Scala’s `for`-expression are mapped likewise to functions on the types used.

-Thorsten

These are other real life examples from a OS X tool I wrote recently:

IEnumerable<Task<Session>> asyncOps = from session in sessions.Values select parseSessionDetails(updater, parser, session);
var ul = node.Descendants().Where(x => x.Name == "ul").First();

For those of you in favor of retaining `where`, how do you feel about adding `while`, `until`, `unless`, etc?

-- E

Ā·Ā·Ā·

On Jun 13, 2016, at 9:23 AM, let var go via swift-evolution <swift-evolution@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.

As a point of order, may I request you stop singling out "the two people who are proposing the change" and discuss the merits of the pitch rather than the people involved in the discussion. Details of the Swift community code of conduct can be found here: Swift.org - Community Overview

As syntactic sugar, the filtering syntax is rarely used, hard to discover, and elevates one style (continue if false) above others (continue if false, break if true, break if false), which are not expressible using similar shorthand. It introduces a fluent style that discourages design comments at the point of use and can be difficult to breakpoint during debugging. The recommended alternative (using a separate guard) addresses all these points: better commenting, better breakpointing and debugging, and fully covers the domain of filtering and early exiting.

In response, I'd like to hear why "continue if false" should be prioritized above the other options and should be retained, or alternatively why the suite should be completed (as in the original discussion with "while") in preference to the advantages accrued by guard.

Thank you,

-- Erica

Ā·Ā·Ā·

On Jun 13, 2016, at 9:44 AM, let var go via swift-evolution <swift-evolution@swift.org> wrote:

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except the two people who are proposing the change) thinks that the "where" clause is the clearest, most expressive way to do it.

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

Something that would help me get on board with this change is more
evidence about what kind of problems it is actually creating.

As best I can tell, this proposal got started because "somewhere" some new
programmers (no one knows how many) expressed some confusion (no one knows
how seriously they were confused, or how long it took them to figure it
out) about how the where clause worked in a for-in loop. For all we know,
once they learned the way it works, they may have said, "Hey that's cool!
I'm gonna use that from now on!"

In other words, you seem to be talking about removing a feature that is
liked by *a lot* people, based on some unsubstantiated reports of user
error that may or may not have been totally unsubstantial.

I don't want new programmers to be confused, either, but the "where"
clause is such a basic programming construct - the keyword is new, but the
idea itself is as old as programming - that I don't mind expecting new
programmers to learn how to use it. The learning curve should be incredibly
short - it is nothing more than a filter operation.

There's something else here that is really important to me, though I don't
know how others feel about it.

Using the guard...continue approach that you are promoting is a code
smell. It puts control-flow logic inside the for-in loop. That is something
I have always tried to avoid. I know that the language allows for it, but I
believe it is bad programming practice. In fact, if you get rid of the
`where` keyword, I'm still not going to use guard...continue. I'll just
filter the collection first and then loop it.

This is quite the statement. It sounds like you'd be for the elimination of
`continue`?

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 10:44 AM, let var go <letvargo@gmail.com> wrote:

It is a code smell for the same reason that messing with the index inside
a for;; loop was a code smell. I was always taught never to do this:

for var i = 0; i < array.count, i++ {
  if iWantThisToLoopAnExtraTime {
    i--
  }
}

Why? Because code like that is confusing. It becomes difficult to know how
many times the loop will execute, what the looping logic is, etc. Sure, I
might get away with it most of the time, but it is bad practice and there
is always a better way to do what you want to do. The only thing that keeps
you from the better way is laziness.

The same is true (albeit to a lesser degree) for the guard...continue. It
may not be as extreme, but it is still a code smell. It divides the
control-flow logic into two parts - one outside the loop, and one inside
the loop, and it suddenly becomes twice as easy to miss something.

Using for-in-where, all of the control-flow logic is on one single line,
and once it is known that "where" operates as a filter operation, it all
works together in a single, harmonious statement that declares exactly what
is going to happen in a way that is totally unambiguous.

So by getting rid of the "where" clause, I believe that you are actually
encouraging bad programming practice. Instead of encouraging the new user
to learn this very simple construct that will ultimately make their code
safer and more expressive without dividing their control-flow logic
unnecessarily into two separate parts, you are encouraging them to just "do
what they know". I think that is terrible, and you are doing them a
disservice.

And from a personal standpoint, you are telling me that I have to write
smelly code, even though there is this perfectly good non-smelly option
sitting right there, because you don't want someone else to have to learn
something.

On Mon, Jun 13, 2016 at 5:29 AM Xiaodi Wu <xiaodi.wu@gmail.com> 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.

On Mon, Jun 13, 2016 at 1:54 AM Jose Cheyo Jimenez <cheyo@masters3d.com> >> wrote:

--1

I think it would be a waste of the community's time to do a formal
review when only two people are in favor of this removal.

'for in where' is so useful especially since we don't have for;;; loops
anymore. I'd say leave this alone; the majority doesn't want this changed.

On Jun 10, 2016, at 10:17 AM, Xiaodi Wu via swift-evolution < >>> swift-evolution@swift.org> 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.

On Fri, Jun 10, 2016 at 12:10 let var go <letvargo@gmail.com> wrote:

Leave it in!

It's a great little tool. I don't use it very often, but when I do it
is because I've decided that in the context of that piece of code it does
exactly what I want it to do with the maximum amount of clarity.

If you don't like it, then don't use it, but I can't see how it
detracts from the language at all.

The *only* argument that I have heard for removing it is that some
people don't immediately intuit how to use it. I didn't have any trouble
with it at all. It follows one of the most basic programming patterns ever:
"For all x in X, if predicate P is true, do something." The use of the
keyword "where" makes perfect sense in that context, and when I read it out
loud, it sounds natural: "For all x in X where P, do something." That is an
elegant, succinct, and clear way of stating exactly what I want my program
to do.

I don't doubt that it has caused some confusion for some people, but
I'm not sold that that is a good enough reason to get rid of it. It seems
strange to get rid of a tool because not everyone understands how to use it
immediately, without ever having to ask a single question. As long as its
not a dangerous tool (and it isn't), then keep it in the workshop for those
times when it comes in handy. And even if there is some initial confusion,
it doesn't sound like it lasted that long. It's more like, "Does this work
like X, or does this work like Y? Let's see...oh, it works like X. Ok."
That's the entire learning curve...about 5 seconds of curiosity followed by
the blissful feeling of resolution.

On Fri, Jun 10, 2016 at 9:32 AM Xiaodi Wu via swift-evolution < >>>> swift-evolution@swift.org> wrote:

On Fri, Jun 10, 2016 at 11:23 AM, Sean Heber via swift-evolution < >>>>> swift-evolution@swift.org> wrote:

> 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.

Weird. My own Swift projects (not on Github :P) use ā€œwhereā€ all the
time with for loops. I really like it and think it reads *and* writes far
better as well as makes for nicer one-liners. In one project, by rough
count, I have about 20 that use ā€œwhereā€ vs. 40 in that same project not
using ā€œwhereā€.

In another smaller test project, there are only 10 for loops, but
even so one still managed to use where.

Not a lot of data without looking at even more projects, I admit, but
this seems to suggest that the usage of ā€œwhereā€ is going to be very
developer-dependent. Perhaps there’s some factor of prior background at
work here? (I’ve done a lot of SQL in another life, for example.)

That is worrying if true, because it suggests that it's enabling
'dialects' of Swift, an explicit anti-goal of the language.

I feel like ā€œwhereā€ is a more declarative construct and that we
should be encouraging that way of thinking in general. When using it, it
feels like ā€œmagicā€ for some reason - even though there’s nothing special
about it. It feels like I’ve made the language work *for me* a little bit
rather than me having to contort my solution to the will of the language.
This may be highly subjective.

l8r
Sean

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

>
> 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.

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 12:24 PM, Haravikk <swift-evolution@haravikk.me> wrote:

> On 13 Jun 2016, at 13:28, Xiaodi Wu via swift-evolution < > swift-evolution@swift.org> wrote:

Suport Haravikk's opinion, just wanted to add:

> Besides, the main argument for it being confusing comes from its use in both while and for loops,

The other main argument was that it is not clear (for some beginners, who never see simple SELECT * FROM .. WHERE .. clause and don't want to check in Swift documentation or in playground) if `where` in for-in loop means 'continue if false' or 'break if false". In this case I believe we can discuss if 'where' should be renamed to something more obvious. But not to remove the feature because of this.

Ā·Ā·Ā·

On 13.06.2016 20:24, Haravikk via swift-evolution wrote:

On 13 Jun 2016, at 13:28, Xiaodi Wu via swift-evolution <swift-evolution@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, 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.
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

See the benchmarks me and Erica have posted here a few days back - even with the lazy accessor, if you decided to use filter(_:), you lost 10+% of performance. Correct way to do this without `where` and without performance penalization is to use guard within the for-in loop.

10% on a microbenchmark repeater 4000000 times is hardly a justification for going on way or the other.

You're right: 10% on a microbenchmark isn't the best possible data. If you have better data, we are all ears.

I never said that it's a deal-breaker, but it is definitely something to consider. Since we're discussing performance of the loop itself, you can't perform much in the body of the for loop since it would skew the result (obviously).

I've previously noted that if/guard-continue come in really close speed-wise, which makes them candidates for a fix-it in case `where` is indeed removed.

My response here was solely to Jean-Daniel's note that he mustn't forget to include the lazy accessor, pointing out that even the lazy accessor is slower than using an inline check.

Ā·Ā·Ā·

On Jun 13, 2016, at 9:59 PM, Brent Royal-Gordon <brent@architechies.com> wrote:

--
Brent Royal-Gordon
Architechies

I was not advocating the lack of constraints, programmers like all other
artists (and engineers, which are artists too ;)), but that the beauty is
the moderation of the two extremes :). ... and that architects leave the
problems you are talking about to the structural engineer :P.

Gravity is a constrain, but a different one than having to use only a
certain pencil to do your sketches with and only being able to use Windows
95 OSR 3 to work on or even weirder limitations.

The question is, does removing `where` feel to you like going from OS X
10.11 to Windows 95, or is it more like going from OS X 10.11.4 to OS X
10.11.3?

Ā·Ā·Ā·

On Fri, Jun 10, 2016 at 2:06 PM, Goffredo Marocchi <panajev@gmail.com> wrote:

On Fri, Jun 10, 2016 at 7:59 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Fri, Jun 10, 2016 at 1:11 PM, Goffredo Marocchi <panajev@gmail.com> >> wrote:

I think sometimes the community in this mailing list loses sight on the
fact that coding is a creative endeavour much similar to architectural
design or painting. There may be math and well researched and structured
ideas in place, but it requires creativity too.

Architects are constrained to craft buildings that will stand in the face
of gravity, and even painters don't have pigments for every color visible
to the human eye. There's a wonderful novel, _Gadsby_, written without the
letter 'e'; I haven't read it but I understand it's truly an
accomplishment. This is not so drastic here. In this case, the apt analogy
would be that we find the letter 'a with circle on top' to be posing some
pesky problems; do you think you could write a novel in English without
using 'a with circle on top'? I wager that your creativity will not suffer
(unless your novel describes a trip to IKEA, in which case I'm sorry).

Trying to force a strict one size fits all The One True standard usually
ends up fragmenting the standard further, by adding yet another take on
what is the most orthodox implementation and who are the heretics...

I do not think dismissing the idea of having more than one way of
skinning the proverbial cat as an anti-goal is doing a good service to the
community or the language as it completely disregards context, people
differing idea of the subjective best coding style and patterns (which
pattern do I use? Which algorithm do I use to sort this data set with? A
good engineer will give you a direct and concise answer, but a better one
will say "it depends... What's the context? What is the problem I need to
solve, what are the constraints and the data set I am working on?").

The way some users seem to want Swift to follow sounds like protecting
users from mistakes by sometimes removing the ability which could lead to
mistakes in the first place, but that removes all the good things you could
do if you were to trust developers with the extra responsibility.

Sent from my iPhone

On 10 Jun 2016, at 18:30, let var go via swift-evolution < >>> swift-evolution@swift.org> wrote:

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@gmail.com> 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.

On Fri, Jun 10, 2016 at 12:10 let var go <letvargo@gmail.com> wrote:

Leave it in!

It's a great little tool. I don't use it very often, but when I do it
is because I've decided that in the context of that piece of code it does
exactly what I want it to do with the maximum amount of clarity.

If you don't like it, then don't use it, but I can't see how it
detracts from the language at all.

The *only* argument that I have heard for removing it is that some
people don't immediately intuit how to use it. I didn't have any trouble
with it at all. It follows one of the most basic programming patterns ever:
"For all x in X, if predicate P is true, do something." The use of the
keyword "where" makes perfect sense in that context, and when I read it out
loud, it sounds natural: "For all x in X where P, do something." That is an
elegant, succinct, and clear way of stating exactly what I want my program
to do.

I don't doubt that it has caused some confusion for some people, but
I'm not sold that that is a good enough reason to get rid of it. It seems
strange to get rid of a tool because not everyone understands how to use it
immediately, without ever having to ask a single question. As long as its
not a dangerous tool (and it isn't), then keep it in the workshop for those
times when it comes in handy. And even if there is some initial confusion,
it doesn't sound like it lasted that long. It's more like, "Does this work
like X, or does this work like Y? Let's see...oh, it works like X. Ok."
That's the entire learning curve...about 5 seconds of curiosity followed by
the blissful feeling of resolution.

On Fri, Jun 10, 2016 at 9:32 AM Xiaodi Wu via swift-evolution < >>>>> swift-evolution@swift.org> wrote:

On Fri, Jun 10, 2016 at 11:23 AM, Sean Heber via swift-evolution < >>>>>> swift-evolution@swift.org> wrote:

> 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.

Weird. My own Swift projects (not on Github :P) use ā€œwhereā€ all the
time with for loops. I really like it and think it reads *and* writes far
better as well as makes for nicer one-liners. In one project, by rough
count, I have about 20 that use ā€œwhereā€ vs. 40 in that same project not
using ā€œwhereā€.

In another smaller test project, there are only 10 for loops, but
even so one still managed to use where.

Not a lot of data without looking at even more projects, I admit,
but this seems to suggest that the usage of ā€œwhereā€ is going to be very
developer-dependent. Perhaps there’s some factor of prior background at
work here? (I’ve done a lot of SQL in another life, for example.)

That is worrying if true, because it suggests that it's enabling
'dialects' of Swift, an explicit anti-goal of the language.

I feel like ā€œwhereā€ is a more declarative construct and that we
should be encouraging that way of thinking in general. When using it, it
feels like ā€œmagicā€ for some reason - even though there’s nothing special
about it. It feels like I’ve made the language work *for me* a little bit
rather than me having to contort my solution to the will of the language.
This may be highly subjective.

l8r
Sean

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

-1

* Swift is explicitly a C-family language. In most or all other C-family
languages, for loop statements allow specification of conditions for
exiting the loop but not for filtering. Therefore, Swift's use of `where`
is unprecedented and needs to be learned anew by every user of Swift.

When was this decided? I distinctly remember some bloke under Craig
Federighi’s hair saying that it was time to ā€œmove beyondā€ C and essentially
ditch legacy conventions which no longer make sense.

I think you misunderstood my argument here. I don't mean that we should
yoke ourselves to C conventions, and we should absolutely ditch C
convention when it doesn't make sense. The big-picture argument here is
that `where` doesn't pass the bar of correcting a C convention that no
longer makes sense.

FWIW, on the topic of syntax choices, here is what Chris Lattner had to
say on this list:

Kevin got it exa*c*tly right, but I’d expand that last bit a bit to:

ā€œā€¦ pi*c*king the one that is most familiar to programmers in the
extended *C* *family* is a good idea.["]
The extended *C* *family* of language (whi*c*h in*c*ludes *C*, *C*++,
Obj*C*, but also *C*#, Java, Javas*c*ript, and more) is
an extremely popular and widely used set of languages that have a lot of
surfa*c*e-level similarity. I
don’t *c*laim to know the design rationale of all of these languages,
but I surmise that this is not an
a*c**c*ident: programmers move around and work in different languages,
and this allows a non-expert in the
language to understand what is going on. While there are things about
*C* that are really unfortunate IMO
(e.g. the de*c*larator/de*c*laration spe*c*ifier part of the grammar)
there is a lot of goodness in the basi
*c*operator set, fo*c*us on dot syntax, and more.
I do agree that there are some benefits to dit*c*hing bra*c*es and
relying on indentation instead, but there are
also downsides. Deviating from the *C* *family* in this respe*c*t would
have to provide **overwhelmingly** large
advantages for us to take su*c*h a plunge, and they simply don’t exist.

As I understand it, Swift is a new language with new conventions. It is
desirable to align as many of those as possible with existing conventions
so as to be easily learned, but if you limit Swift to other languages
conventions you deny it any identity. Did Python ask anybody’s opinion
before dropping curly-braces? Did people learn whatever Perl is supposed to
be? Look at C’s hieroglyphic for loops!

I don't think we disagree here.

Realistically, ā€œfor … in … whileā€ is not going to cause incredible
confusion. Removing it would cause a lot of frustration. You can’t on the
one hand say our users are comfortable with the axioms of C’s hieroglyphic
loops, and on the other hand say ā€œfor x in y while" is confusing.

Again, as I said, once you've mastered something, by definition you find
it not confusing. Why should we doom x% of new users to writing a loop
incorrectly at least once when we don't have to?

Ah, but if you’re not ā€œdoomedā€ to failing once, how will you ever master
anything? Nobody knew how to write a C for-loop until someone showed them
(and even then…). Nobody is going to just open a REPL and start writing
code, with zero prior understanding of what Swift syntax looks like.

The thought here is along the lines of what Chris said, quoted above, and
repeated here: "The extended C family of language [...] is an extremely
popular and widely used set[;] programmers move around and work in
different languages, and [aligning to expectations arising from other C
family languages] allows a non-expert in the language to understand what is
going on." By contrast, the `where` clause violates that expectation and I
do not see "overwhelmingly large advantages" for doing so.

What about C#'s `where` then? As C# is a member of the C family languages
`where` is not violating expectations!

Where is not exactly a part of c# it belongs to linq

And that is not a part of C#??

SQL is a domain-specific language, and LINQ is an internal domain-specific
language with a language extension for C#. Neither is a general purpose
language.

Your example actually goes to one of Laurent's points. Should the Swift
core team or an enterprising community member propose a set of similarly
powerful tools, along with a set of language extensions that add syntactic
sugar for them, I (and I think Laurent, if I understand him correctly)
would absolutely be in favor of such an addition. But as it is, `where` is
an odd duckling. Just as you say, it looks like a component of a query
language, but it does no such thing. In a for loop, it does some filtering,
but until recently it functioned like a comma in `while` loops. Look at
those other keywords which make this sugar possible in C#: in your example,
`from` and `select`. We don't have any of that intrastructure in Swift.

IMHO the team has taken an Ockham Axe to the grammar: in the presence of
multiple ways to produce the same or an acceptable stand-in (for eg when
the only difference is an acceptable temporary perf setback), then the
solution requiring the least assumptions on the compiler wins.

I would even extend this rule with the corollary that between an
assumption materialized as a type checker rule and an assumption
materialized as a full blown extra language keyword, there might be a bias
to accept the former if it kills the latter. But this is just my personal
inference of what their decision heuristic might be based solely on what I
saw. My sole interest in trying to understand their decision making process
is to try to avoid proposals that have little to no chance to go anywhere,
as well as trying to present ones that will align better with where the
language is going.

In this instance, WHERE is a heavy assumption on the compiler for no
greater gain than filters can provide. So I think we save the WHERE keyword
for an outcome that will be really worth it! Something along the idea of
Linq, but with a proper Swift feel to it. What does it look like? I cannot
say yet. But the good news is that having taken WHERE out now will make
that next step a purely additive process (nothing will be taken out then,
but a big thing will be gained).

I am all for extending `for` to be more like Scala’s `for`-expression or
Haskell’s `do`-notation. LINQ might be too focused on querying.
Extending the current `where` to be syntax sugar for `filter` would be
quite straightforward, though, so I’m not sure whether removing it first is
really necessary.
That was not object of the pitch to retire `where` from `for`-loops,
though. Instead the argument was (and still is) that `where` might be
misunderstood there by beginners and should therefore be removed. This
argument would apply to an extended `where` unchanged, because I can still
write the exact same code as being criticized now and can even do more
complicated things which would by even more hard to understand for
beginners.
That’s the argument I disagree with.

The following is an example from MSDN with `where` clearly beaing a

keyword:

*var* numQuery = *from* num *in* numbers *where* (num % 2) == 0 *select* num;

Here is food for your thoughts, you think WHERE is a keyword?! then look
at this:

var numbers = new int{0,1,23,4,5,6,7,87,9};
var numQuery = from num in numbers where (num % 2) == 0 select num;

Program does not compile:

// Error CS1935: An implementation of `Where' query expression pattern
could not be found. Are you missing `System.Linq' using directive or
`System.Core.dll' assembly reference? (CS1935) (SessionsFinder)

using System.Linq;
var numbers = new int{0,1,23,4,5,6,7,87,9};
var numQuery = from num in numbers where (num % 2) == 0 select num;

That program does compiles and runs fine. This tells you that ā€œwhere" is
not at all the ordinary keyword that it appears to be. hence my ā€œit is not
C# per-se, it is Linqā€.

Digging into C# Features That Support LINQ - C# | Microsoft Learn and
C# Keywords - C# | Microsoft Learn tells me the
following:
(1) `from`, `where` etc. are contextual keywords, but they are nonetheless
keywords of C# and expressly *not* a specific feature of LINQ: "Although
these new features are all used to a degree with LINQ queries, they are not
limited to LINQ and can be used in any context where you find them useful."
(2) the compiler translates them into standard method calls (like Scala’s
`for`-expression or Haskell’s `do`-notation). That is an integral part of
C#.
(3) your error message originates from not having an implementation of a
`Where`-method in scope. You could have provided one yourself instead of
`using System.Linq`.

Of course the compiler knows about it... My exact wording was "ordinary
keyword" implying, "it is one, just not in the sense you are giving it
right now". Knowing you would want to dig further I had to find a
description that was true albeit leaving the fine details out (i doubt too
may actually care about the distinction between contextual and
non-contextual kwd, or the fact that sql is turing complete ;) ).

My thought is to accept the downgrading from its current status because
its complete behavior is limited and hetched in blood inside the grammar,
therefore not extensible without grammar alterations; thereby leaving the
door open for a future re-introduction ala-Linq in v4+. I use the term
"ala-linq" as a placeholder for "some sort of more dynamic behavior
resulting from a close collaboration between compiler, stdlib, runtime and
user code". And i still believe nobody outside doug, joe, chris, or jordan
cares about the actual implementation details.

Again, this is just a personal view on what looks IMHO like a great
opportunity.

Well said. Like you, I don't know what the core team's feelings would be
with respect to contextual sugar for domain-specific uses. IMHO, it is a
very neat concept. If it does arrive in Swift 4+, then `where` as sugar for
`filter()` should come with that. If that's not the direction that the core
team wants to go, I fail to see why filtering a sequence specifically as
part of a loop should be privileged above any other useful operation that
would have a similarly strong claim to sugar.

Ā·Ā·Ā·

On Sun, Jun 12, 2016 at 9:23 AM, L. Mihalkovic <laurent.mihalkovic@gmail.com > wrote:

On Jun 12, 2016, at 3:21 PM, Thorsten Seitz <tseitz42@icloud.com> wrote:
Am 12.06.2016 um 12:02 schrieb L Mihalkovic <laurent.mihalkovic@gmail.com > >:
On Jun 11, 2016, at 11:45 PM, Xiaodi Wu <xiaodi.wu@gmail.com> wrote:
On Sat, Jun 11, 2016 at 3:37 PM, Thorsten Seitz <tseitz42@icloud.com> > wrote:

Am 11.06.2016 um 22:29 schrieb L. Mihalkovic < >> laurent.mihalkovic@gmail.com>:
On Jun 11, 2016, at 9:53 PM, Thorsten Seitz via swift-evolution < >> swift-evolution@swift.org> wrote:
Am 10.06.2016 um 18:28 schrieb Xiaodi Wu via swift-evolution < >> swift-evolution@swift.org>:
On Fri, Jun 10, 2016 at 6:10 AM, Karl <razielim@gmail.com> wrote:

And if you still wonder, then rewrite the code so that ā€œWHEREā€ no longer
looks like a keyword:

var numQuery2 = numbers.Where( num => num %2 == 0); // exact same result
as numQuery1

That’s exactly what I expected as it is the standard way syntactic
language sugar is mapped to customizable behavior. Haskell’s `do`-notation
or Scala’s `for`-expression are mapped likewise to functions on the types
used.

-Thorsten

These are other real life examples from a OS X tool I wrote recently:

IEnumerable<Task<Session>> asyncOps = from session in sessions.Values
select parseSessionDetails(updater, parser, session);
var ul = node.Descendants().Where(x => x.Name == "ul").First();

I think that ā€œwhileā€ could be potentially useful, but since it hasn’t existed, I haven’t really considered what code might look like if that was possible. :P

l8r
Sean

Ā·Ā·Ā·

On Jun 13, 2016, at 10:26 AM, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

On Jun 13, 2016, at 9:23 AM, let var go via swift-evolution <swift-evolution@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

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

As a point of order, may I request you stop singling out "the two people
who are proposing the change" and discuss the merits of the pitch rather
than the people involved in the discussion. Details of the Swift community
code of conduct can be found here:
Swift.org - Community Overview

As syntactic sugar, the filtering syntax is rarely used, hard to discover,
and elevates one style (continue if false) above others (continue if false,
break if true, break if false

...and, a surprising number I noted from doing a rough GitHub search (many
more than I thought I would see): return if true, return if false,
fatalError if true, fatalError if false.

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 10:54 AM, Erica Sadun <erica@ericasadun.com> wrote:

On Jun 13, 2016, at 9:44 AM, let var go via swift-evolution < > swift-evolution@swift.org> wrote:

), which are not expressible using similar shorthand. It introduces a
fluent style that discourages design comments at the point of use and can
be difficult to breakpoint during debugging. The recommended alternative
(using a separate guard) addresses all these points: better commenting,
better breakpointing and debugging, and fully covers the domain of
filtering and early exiting.

In response, I'd like to hear why "continue if false" should be
prioritized above the other options and should be retained, or
alternatively why the suite should be completed (as in the original
discussion with "while") in preference to the advantages accrued by guard.

Thank you,

-- Erica

I sincerely apologize for singling people out. I will avoid it in the
future. I can see how it might personalize things in a way that is bad. I
appreciate you pointing out my mistake :)

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 8:54 AM Erica Sadun <erica@ericasadun.com> wrote:

On Jun 13, 2016, at 9:44 AM, let var go via swift-evolution < > swift-evolution@swift.org> wrote:

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

As a point of order, may I request you stop singling out "the two people
who are proposing the change" and discuss the merits of the pitch rather
than the people involved in the discussion. Details of the Swift community
code of conduct can be found here:
Swift.org - Community Overview

As syntactic sugar, the filtering syntax is rarely used, hard to discover,
and elevates one style (continue if false) above others (continue if false,
break if true, break if false), which are not expressible using similar
shorthand. It introduces a fluent style that discourages design comments at
the point of use and can be difficult to breakpoint during debugging. The
recommended alternative (using a separate guard) addresses all these
points: better commenting, better breakpointing and debugging, and fully
covers the domain of filtering and early exiting.

In response, I'd like to hear why "continue if false" should be
prioritized above the other options and should be retained, or
alternatively why the suite should be completed (as in the original
discussion with "while") in preference to the advantages accrued by guard.

Thank you,

-- Erica

Moreover, I should add, if your goal is to eliminate the possibility of
continuing and breaking from inside the loop, `.forEach()` does that
exactly, so your argument would be for the elimination of `for..in`
altogether.

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 10:55 Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Mon, Jun 13, 2016 at 10:44 AM, let var go <letvargo@gmail.com> wrote:

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

Something that would help me get on board with this change is more
evidence about what kind of problems it is actually creating.

As best I can tell, this proposal got started because "somewhere" some
new programmers (no one knows how many) expressed some confusion (no one
knows how seriously they were confused, or how long it took them to figure
it out) about how the where clause worked in a for-in loop. For all we
know, once they learned the way it works, they may have said, "Hey that's
cool! I'm gonna use that from now on!"

In other words, you seem to be talking about removing a feature that is
liked by *a lot* people, based on some unsubstantiated reports of user
error that may or may not have been totally unsubstantial.

I don't want new programmers to be confused, either, but the "where"
clause is such a basic programming construct - the keyword is new, but the
idea itself is as old as programming - that I don't mind expecting new
programmers to learn how to use it. The learning curve should be incredibly
short - it is nothing more than a filter operation.

There's something else here that is really important to me, though I
don't know how others feel about it.

Using the guard...continue approach that you are promoting is a code
smell. It puts control-flow logic inside the for-in loop. That is something
I have always tried to avoid. I know that the language allows for it, but I
believe it is bad programming practice. In fact, if you get rid of the
`where` keyword, I'm still not going to use guard...continue. I'll just
filter the collection first and then loop it.

This is quite the statement. It sounds like you'd be for the elimination
of `continue`?

It is a code smell for the same reason that messing with the index inside
a for;; loop was a code smell. I was always taught never to do this:

for var i = 0; i < array.count, i++ {
  if iWantThisToLoopAnExtraTime {
    i--
  }
}

Why? Because code like that is confusing. It becomes difficult to know
how many times the loop will execute, what the looping logic is, etc. Sure,
I might get away with it most of the time, but it is bad practice and there
is always a better way to do what you want to do. The only thing that keeps
you from the better way is laziness.

The same is true (albeit to a lesser degree) for the guard...continue. It
may not be as extreme, but it is still a code smell. It divides the
control-flow logic into two parts - one outside the loop, and one inside
the loop, and it suddenly becomes twice as easy to miss something.

Using for-in-where, all of the control-flow logic is on one single line,
and once it is known that "where" operates as a filter operation, it all
works together in a single, harmonious statement that declares exactly what
is going to happen in a way that is totally unambiguous.

So by getting rid of the "where" clause, I believe that you are actually
encouraging bad programming practice. Instead of encouraging the new user
to learn this very simple construct that will ultimately make their code
safer and more expressive without dividing their control-flow logic
unnecessarily into two separate parts, you are encouraging them to just "do
what they know". I think that is terrible, and you are doing them a
disservice.

And from a personal standpoint, you are telling me that I have to write
smelly code, even though there is this perfectly good non-smelly option
sitting right there, because you don't want someone else to have to learn
something.

On Mon, Jun 13, 2016 at 5:29 AM Xiaodi Wu <xiaodi.wu@gmail.com> 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.

On Mon, Jun 13, 2016 at 1:54 AM Jose Cheyo Jimenez <cheyo@masters3d.com> >>> wrote:

--1

I think it would be a waste of the community's time to do a formal
review when only two people are in favor of this removal.

'for in where' is so useful especially since we don't have for;;; loops
anymore. I'd say leave this alone; the majority doesn't want this changed.

On Jun 10, 2016, at 10:17 AM, Xiaodi Wu via swift-evolution < >>>> swift-evolution@swift.org> 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.

On Fri, Jun 10, 2016 at 12:10 let var go <letvargo@gmail.com> wrote:

Leave it in!

It's a great little tool. I don't use it very often, but when I do it
is because I've decided that in the context of that piece of code it does
exactly what I want it to do with the maximum amount of clarity.

If you don't like it, then don't use it, but I can't see how it
detracts from the language at all.

The *only* argument that I have heard for removing it is that some
people don't immediately intuit how to use it. I didn't have any trouble
with it at all. It follows one of the most basic programming patterns ever:
"For all x in X, if predicate P is true, do something." The use of the
keyword "where" makes perfect sense in that context, and when I read it out
loud, it sounds natural: "For all x in X where P, do something." That is an
elegant, succinct, and clear way of stating exactly what I want my program
to do.

I don't doubt that it has caused some confusion for some people, but
I'm not sold that that is a good enough reason to get rid of it. It seems
strange to get rid of a tool because not everyone understands how to use it
immediately, without ever having to ask a single question. As long as its
not a dangerous tool (and it isn't), then keep it in the workshop for those
times when it comes in handy. And even if there is some initial confusion,
it doesn't sound like it lasted that long. It's more like, "Does this work
like X, or does this work like Y? Let's see...oh, it works like X. Ok."
That's the entire learning curve...about 5 seconds of curiosity followed by
the blissful feeling of resolution.

On Fri, Jun 10, 2016 at 9:32 AM Xiaodi Wu via swift-evolution < >>>>> swift-evolution@swift.org> wrote:

On Fri, Jun 10, 2016 at 11:23 AM, Sean Heber via swift-evolution < >>>>>> swift-evolution@swift.org> wrote:

> 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.

Weird. My own Swift projects (not on Github :P) use ā€œwhereā€ all the
time with for loops. I really like it and think it reads *and* writes far
better as well as makes for nicer one-liners. In one project, by rough
count, I have about 20 that use ā€œwhereā€ vs. 40 in that same project not
using ā€œwhereā€.

In another smaller test project, there are only 10 for loops, but
even so one still managed to use where.

Not a lot of data without looking at even more projects, I admit,
but this seems to suggest that the usage of ā€œwhereā€ is going to be very
developer-dependent. Perhaps there’s some factor of prior background at
work here? (I’ve done a lot of SQL in another life, for example.)

That is worrying if true, because it suggests that it's enabling
'dialects' of Swift, an explicit anti-goal of the language.

I feel like ā€œwhereā€ is a more declarative construct and that we
should be encouraging that way of thinking in general. When using it, it
feels like ā€œmagicā€ for some reason - even though there’s nothing special
about it. It feels like I’ve made the language work *for me* a little bit
rather than me having to contort my solution to the will of the language.
This may be highly subjective.

l8r
Sean

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

No, I wouldn't eliminate 'continue'. Even though I consider it a
sub-optimal solution, I would keep it in the language. Why? A couple of
reasons:

1) I don't like it, but even 'continue' may be the best available solution
in the context of a particular problem. I will look for other options
first, but I don't rule out the possibility that there might come a time
when it is the right tool for the job.

2) Some people like it. Not everyone feels the same way about it as me.
Some of the people who like it are better programmers than me. I have a lot
to learn, and someday I might discover that I love 'continue' after all.
Until then, live-and-let-live is what I say. Everyone should control their
own flow :) Keep your hands off my 'where' and I'll keep my hands off your
'continue' :)

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 8:56 AM Xiaodi Wu <xiaodi.wu@gmail.com> wrote:

On Mon, Jun 13, 2016 at 10:44 AM, let var go <letvargo@gmail.com> wrote:

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

Something that would help me get on board with this change is more
evidence about what kind of problems it is actually creating.

As best I can tell, this proposal got started because "somewhere" some
new programmers (no one knows how many) expressed some confusion (no one
knows how seriously they were confused, or how long it took them to figure
it out) about how the where clause worked in a for-in loop. For all we
know, once they learned the way it works, they may have said, "Hey that's
cool! I'm gonna use that from now on!"

In other words, you seem to be talking about removing a feature that is
liked by *a lot* people, based on some unsubstantiated reports of user
error that may or may not have been totally unsubstantial.

I don't want new programmers to be confused, either, but the "where"
clause is such a basic programming construct - the keyword is new, but the
idea itself is as old as programming - that I don't mind expecting new
programmers to learn how to use it. The learning curve should be incredibly
short - it is nothing more than a filter operation.

There's something else here that is really important to me, though I
don't know how others feel about it.

Using the guard...continue approach that you are promoting is a code
smell. It puts control-flow logic inside the for-in loop. That is something
I have always tried to avoid. I know that the language allows for it, but I
believe it is bad programming practice. In fact, if you get rid of the
`where` keyword, I'm still not going to use guard...continue. I'll just
filter the collection first and then loop it.

This is quite the statement. It sounds like you'd be for the elimination
of `continue`?

It is a code smell for the same reason that messing with the index inside
a for;; loop was a code smell. I was always taught never to do this:

for var i = 0; i < array.count, i++ {
  if iWantThisToLoopAnExtraTime {
    i--
  }
}

Why? Because code like that is confusing. It becomes difficult to know
how many times the loop will execute, what the looping logic is, etc. Sure,
I might get away with it most of the time, but it is bad practice and there
is always a better way to do what you want to do. The only thing that keeps
you from the better way is laziness.

The same is true (albeit to a lesser degree) for the guard...continue. It
may not be as extreme, but it is still a code smell. It divides the
control-flow logic into two parts - one outside the loop, and one inside
the loop, and it suddenly becomes twice as easy to miss something.

Using for-in-where, all of the control-flow logic is on one single line,
and once it is known that "where" operates as a filter operation, it all
works together in a single, harmonious statement that declares exactly what
is going to happen in a way that is totally unambiguous.

So by getting rid of the "where" clause, I believe that you are actually
encouraging bad programming practice. Instead of encouraging the new user
to learn this very simple construct that will ultimately make their code
safer and more expressive without dividing their control-flow logic
unnecessarily into two separate parts, you are encouraging them to just "do
what they know". I think that is terrible, and you are doing them a
disservice.

And from a personal standpoint, you are telling me that I have to write
smelly code, even though there is this perfectly good non-smelly option
sitting right there, because you don't want someone else to have to learn
something.

On Mon, Jun 13, 2016 at 5:29 AM Xiaodi Wu <xiaodi.wu@gmail.com> 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.

On Mon, Jun 13, 2016 at 1:54 AM Jose Cheyo Jimenez <cheyo@masters3d.com> >>> wrote:

--1

I think it would be a waste of the community's time to do a formal
review when only two people are in favor of this removal.

'for in where' is so useful especially since we don't have for;;; loops
anymore. I'd say leave this alone; the majority doesn't want this changed.

On Jun 10, 2016, at 10:17 AM, Xiaodi Wu via swift-evolution < >>>> swift-evolution@swift.org> 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.

On Fri, Jun 10, 2016 at 12:10 let var go <letvargo@gmail.com> wrote:

Leave it in!

It's a great little tool. I don't use it very often, but when I do it
is because I've decided that in the context of that piece of code it does
exactly what I want it to do with the maximum amount of clarity.

If you don't like it, then don't use it, but I can't see how it
detracts from the language at all.

The *only* argument that I have heard for removing it is that some
people don't immediately intuit how to use it. I didn't have any trouble
with it at all. It follows one of the most basic programming patterns ever:
"For all x in X, if predicate P is true, do something." The use of the
keyword "where" makes perfect sense in that context, and when I read it out
loud, it sounds natural: "For all x in X where P, do something." That is an
elegant, succinct, and clear way of stating exactly what I want my program
to do.

I don't doubt that it has caused some confusion for some people, but
I'm not sold that that is a good enough reason to get rid of it. It seems
strange to get rid of a tool because not everyone understands how to use it
immediately, without ever having to ask a single question. As long as its
not a dangerous tool (and it isn't), then keep it in the workshop for those
times when it comes in handy. And even if there is some initial confusion,
it doesn't sound like it lasted that long. It's more like, "Does this work
like X, or does this work like Y? Let's see...oh, it works like X. Ok."
That's the entire learning curve...about 5 seconds of curiosity followed by
the blissful feeling of resolution.

On Fri, Jun 10, 2016 at 9:32 AM Xiaodi Wu via swift-evolution < >>>>> swift-evolution@swift.org> wrote:

On Fri, Jun 10, 2016 at 11:23 AM, Sean Heber via swift-evolution < >>>>>> swift-evolution@swift.org> wrote:

> 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.

Weird. My own Swift projects (not on Github :P) use ā€œwhereā€ all the
time with for loops. I really like it and think it reads *and* writes far
better as well as makes for nicer one-liners. In one project, by rough
count, I have about 20 that use ā€œwhereā€ vs. 40 in that same project not
using ā€œwhereā€.

In another smaller test project, there are only 10 for loops, but
even so one still managed to use where.

Not a lot of data without looking at even more projects, I admit,
but this seems to suggest that the usage of ā€œwhereā€ is going to be very
developer-dependent. Perhaps there’s some factor of prior background at
work here? (I’ve done a lot of SQL in another life, for example.)

That is worrying if true, because it suggests that it's enabling
'dialects' of Swift, an explicit anti-goal of the language.

I feel like ā€œwhereā€ is a more declarative construct and that we
should be encouraging that way of thinking in general. When using it, it
feels like ā€œmagicā€ for some reason - even though there’s nothing special
about it. It feels like I’ve made the language work *for me* a little bit
rather than me having to contort my solution to the will of the language.
This may be highly subjective.

l8r
Sean

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

_______________________________________________

swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

`while`, `until` and `unless` all implicate that the loop should break when the condition (or its negation) is met.

On the other hand, `where` as it is seems logical to me. Anyone who considers serious coding is likely to have basic knowledge of mathematics, so something such as

āˆ€x ∈ X, x > 0

which translates into

for x in X where x > 0

in Swift, which is pretty much how you'd read the mathematical statement. Yes, there is a comma, not `where` in the formula but when reading, you say "where" (unless you say "every x greater than zero").

Ā·Ā·Ā·

On Jun 13, 2016, at 5:26 PM, Erica Sadun <erica@ericasadun.com> wrote:

On Jun 13, 2016, at 9:23 AM, let var go via swift-evolution <swift-evolution@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

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except
the two people who are proposing the change) thinks that the "where" clause
is the clearest, most expressive way to do it.

As a point of order, may I request you stop singling out "the two people
who are proposing the change" and discuss the merits of the pitch rather
than the people involved in the discussion. Details of the Swift community
code of conduct can be found here:
Swift.org - Community Overview

As syntactic sugar, the filtering syntax is rarely used, hard to discover,
and elevates one style (continue if false) above others (continue if false,
break if true, break if false), which are not expressible using similar
shorthand. It introduces a fluent style that discourages design comments at
the point of use and can be difficult to breakpoint during debugging. The
recommended alternative (using a separate guard) addresses all these
points: better commenting, better breakpointing and debugging, and fully
covers the domain of filtering and early exiting.

In response, I'd like to hear why "continue if false" should be
prioritized above the other options and should be retained, or
alternatively why the suite should be completed (as in the original
discussion with "while") in preference to the advantages accrued by guard.

The way you broke it down into the four different categories was helpful to
me - I hadn't thought of it that way before. Here's may take on it:

   - "continue if false"
   - This is the current 'where` keyword.
   - "continue if true"
      - This is the inverse of the current 'where' option. Because it is
      the inverse, it doesn't need a separate keyword. You just add the logical
      not '!' to the predicate, or just reverse the test, to obtain the inverse
      filtering operation.
      - So, for example, `for string in strings where
      string.hasPrefix("somePrefix")` becomes `for string in strings where
      !string.hasPrefix("somePrefix")`; or `for x in xs where x < 5`, becomes
      `for x in xs where x >= 5`
      - Using a single keyword but reversing the predicate isn't the only
      approach but it has the advantage of not polluting the language with
      unnecessary keywords where a single keyword can do the job.
   - "break if false"
      - In this scenario, you start looping through a collection, but exit
      early when some condition is no longer true. It combines a for...in loop
      with a 'while' loop.
      - This construct would allow you to set a condition for early exit
      from the loop. The problem I see with this is that when I need to exit a
      loop early, I usually need to do something else first, like
assign a value
      to a variable, or take some other action. So for example, I might do
      something like this:

var nextEvent: Event?
for event in events {
    if event.time >= now {
        nextEvent = event
        break
    }
}

   - The point is that before I could use 'break', I had to take some
      action (assign a value to nextEvent). So just defining an early exit
      condition wouldn't really work. I'm trying to think of a use-case where I
      would want to exit early without doing anything first, and I can't. Given
      the appropriate use case, however, I could see a place for a keyword that
      did this like 'until', or 'while'. Until then, though, I
wouldn't create a
      keyword for something that doesn't have a common use. Filtering with
      'where' is at least used sometimes, even if it isn't the most common
      pattern on the planet.
   - "break if true"
      - I would apply the same arguments in "break if false"

So I would say that "continue if false" and "continue if true" are
accomplished using the same keyword, and "break if false" and "break if
true" don't have demonstrated use cases that can be solved with a
keyword/predicate combination - early exit usually requires some additional
action other than just exiting which couldn't be easily baked into the
keyword.

Ā·Ā·Ā·

On Mon, Jun 13, 2016 at 8:54 AM Erica Sadun <erica@ericasadun.com> wrote:

On Jun 13, 2016, at 9:44 AM, let var go via swift-evolution < > swift-evolution@swift.org> wrote:

Thank you,

-- Erica

I would say we need a separate meeting where we propose to add them and discuss why we would want them in Swift :).

Ā·Ā·Ā·

Sent from my iPhone

On 13 Jun 2016, at 16:26, Erica Sadun via swift-evolution <swift-evolution@swift.org> wrote:

On Jun 13, 2016, at 9:23 AM, let var go via swift-evolution <swift-evolution@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

_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution

I think we must be reading different discussions.

What I have seen in this discussion is the following:

a) The need to filter a for-in loop doesn't arise that often; but,
b) When it does arise, everyone who has chimed in on this thread (except the two people who are proposing the change) thinks that the "where" clause is the clearest, most expressive way to do it.

As a point of order, may I request you stop singling out "the two people who are proposing the change" and discuss the merits of the pitch rather than the people involved in the discussion. Details of the Swift community code of conduct can be found here: Swift.org - Community Overview

As syntactic sugar, the filtering syntax is rarely used, hard to discover, and elevates one style (continue if false) above others (continue if false, break if true, break if false), which are not expressible using similar shorthand. It introduces a fluent style that discourages design comments at the point of use and can be difficult to breakpoint during debugging. The recommended alternative (using a separate guard) addresses all these points: better commenting, better breakpointing and debugging, and fully covers the domain of filtering and early exiting.

Another point about the narrowness of 'where' beside being only for one of the four true/false continue/break cases, is that it only handle conditions at the top of the loop. Any 'continue' required in the middle of the block (after some processing) has to be handle by the "more powerful/versatile" 'guard' and/or 'if'.

Also if the need arise to do something extra beside 'continue' on the rejects, even something as simple as logging to the console, the 'where' needs to be converted to a 'guard' or 'if'.

Beside these drawbacks, I still think 'where' is nice to have

Dany

Ā·Ā·Ā·

Le 13 juin 2016 Ơ 11:54, Erica Sadun via swift-evolution <swift-evolution@swift.org> a Ʃcrit :

On Jun 13, 2016, at 9:44 AM, let var go via swift-evolution <swift-evolution@swift.org> wrote:

In response, I'd like to hear why "continue if false" should be prioritized above the other options and should be retained, or alternatively why the suite should be completed (as in the original discussion with "while") in preference to the advantages accrued by guard.

Thank you,

-- Erica
_______________________________________________
swift-evolution mailing list
swift-evolution@swift.org
https://lists.swift.org/mailman/listinfo/swift-evolution