Proposal: Replace labels with keywords and "*" suffixes


(Amir Michail) #1

For example:

for* … {
  for** ... {
    for ... {
      …
      if … { break for* }
      ...
      if … { continue for** }
      ...
    }
  }
}

repeat {
  do {
    for … {
      if … { break do }
      if … { continue repeat }
    }
    …
  }
} while …


(Kevin Wooten) #2

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

···

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

For example:

for* … {
for** ... {
   for ... {
     …
     if … { break for* }
     ...
     if … { continue for** }
     ...
   }
}
}

repeat {
do {
   for … {
     if … { break do }
     if … { continue repeat }
   }
   …
}
} while …

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


(Amir Michail) #3

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be uninteresting.

···

On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com> wrote:

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

For example:

for* … {
for** ... {
  for ... {
    …
    if … { break for* }
    ...
    if … { continue for** }
    ...
  }
}
}

repeat {
do {
  for … {
    if … { break do }
    if … { continue repeat }
  }
  …
}
} while …

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


(James Campbell) #4

No

···

On Thu, Dec 10, 2015 at 12:59 PM, Amir Michail via swift-evolution < swift-evolution@swift.org> wrote:

For example:

for* … {
  for** ... {
    for ... {
      …
      if … { break for* }
      ...
      if … { continue for** }
      ...
    }
  }
}

repeat {
  do {
    for … {
      if … { break do }
      if … { continue repeat }
    }
    …
  }
} while …

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

--
 Wizard
james@supmenow.com
+44 7523 279 698


(Austin Zheng) #5

Unlabeled "break" within a do is a compiler error, even if the do is nested
within a different control flow.

If you really hate coming up with label names, just start with L1 and start
counting up. If you really need to come up with that many labeled breaks in
your code, though, I would invite you to step back and think about whether
or not you could refactor your control flow in a way that makes it easier
for others to understand.

Austin

···

On Thu, Dec 10, 2015 at 5:28 AM, Amir Michail via swift-evolution < swift-evolution@swift.org> wrote:

> On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com> wrote:
>
> Curios as to what you see the advantage of this is, over labels? Seems
to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a
label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be
uninteresting.

>
> Given the stated goals of Swift I don’t imagine this would be an
interesting proposal for many.
>
>> On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution < > swift-evolution@swift.org> wrote:
>>
>> For example:
>>
>> for* … {
>> for** ... {
>> for ... {
>> …
>> if … { break for* }
>> ...
>> if … { continue for** }
>> ...
>> }
>> }
>> }
>>
>> repeat {
>> do {
>> for … {
>> if … { break do }
>> if … { continue repeat }
>> }
>> …
>> }
>> } while …
>>
>>
>> _______________________________________________
>> 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


(Adrian Kashivskyy) #6

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Because `do` isn't a loop.

Pozdrawiam – Regards,
Adrian Kashivskyy

···

Wiadomość napisana przez Amir Michail via swift-evolution <swift-evolution@swift.org> w dniu 10.12.2015, o godz. 14:28:

On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com> wrote:

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be uninteresting.

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org> wrote:

For example:

for* … {
for** ... {
for ... {
   …
   if … { break for* }
   ...
   if … { continue for** }
   ...
}
}
}

repeat {
do {
for … {
   if … { break do }
   if … { continue repeat }
}

}
} while …

_______________________________________________
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


(Kevin Wooten) #7

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Because `do` isn't a loop.

Neither is a case but the “break" behaviour is different.

Moreover, you can give do a label to just break out of the do.

As you just said if you think “break” behavior is unclear, you can add a label.

It doesn’t seem to be up for debate that labels provide much more clarity than your proposal. To reduce clarity because you find it annoying to come up with label names is not consistent with the design of the language; which clearly favors clarity.

···

On Dec 10, 2015, at 6:47 AM, Amir Michail <a.michail@me.com> wrote:

On Dec 10, 2015, at 8:45 AM, Adrian Kashivskyy <adrian.kashivskyy@me.com <mailto:adrian.kashivskyy@me.com>> wrote:

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> w dniu 10.12.2015, o godz. 14:28:

On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com <mailto:kdubb@me.com>> wrote:

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be uninteresting.

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

For example:

for* … {
for** ... {
for ... {
   …
   if … { break for* }
   ...
   if … { continue for** }
   ...
}
}
}

repeat {
do {
for … {
   if … { break do }
   if … { continue repeat }
}

}
} while …

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

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


(Amir Michail) #8

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Because `do` isn't a loop.

Neither is a case but the “break" behaviour is different.

Moreover, you can give do a label to just break out of the do.

···

On Dec 10, 2015, at 8:45 AM, Adrian Kashivskyy <adrian.kashivskyy@me.com> wrote:

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> w dniu 10.12.2015, o godz. 14:28:

On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com <mailto:kdubb@me.com>> wrote:

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be uninteresting.

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

For example:

for* … {
for** ... {
for ... {
   …
   if … { break for* }
   ...
   if … { continue for** }
   ...
}
}
}

repeat {
do {
for … {
   if … { break do }
   if … { continue repeat }
}

}
} while …

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

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


(Amir Michail) #9

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Because `do` isn't a loop.

Neither is a case but the “break" behaviour is different.

Moreover, you can give do a label to just break out of the do.

As you just said if you think “break” behavior is unclear, you can add a label.

The point is that Swift currently has inconsistent break behaviour.

···

On Dec 10, 2015, at 8:54 AM, Kevin Wooten <kdubb@me.com> wrote:

On Dec 10, 2015, at 6:47 AM, Amir Michail <a.michail@me.com <mailto:a.michail@me.com>> wrote:

On Dec 10, 2015, at 8:45 AM, Adrian Kashivskyy <adrian.kashivskyy@me.com <mailto:adrian.kashivskyy@me.com>> wrote:

It doesn’t seem to be up for debate that labels provide much more clarity than your proposal. To reduce clarity because you find it annoying to come up with label names is not consistent with the design of the language; which clearly favors clarity.

Pozdrawiam – Regards,
Adrian Kashivskyy

Wiadomość napisana przez Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> w dniu 10.12.2015, o godz. 14:28:

On Dec 10, 2015, at 8:20 AM, Kevin Wooten <kdubb@me.com <mailto:kdubb@me.com>> wrote:

Curios as to what you see the advantage of this is, over labels? Seems to me it only saves a few keystrokes at the expense of clarity.

What “break" currently does can be unclear. For example, “break” without a label in do {…} doesn’t just break out of the do.

Also, I really don’t like coming up with label names. They tend to be uninteresting.

Given the stated goals of Swift I don’t imagine this would be an interesting proposal for many.

On Dec 10, 2015, at 5:59 AM, Amir Michail via swift-evolution <swift-evolution@swift.org <mailto:swift-evolution@swift.org>> wrote:

For example:

for* … {
for** ... {
for ... {
   …
   if … { break for* }
   ...
   if … { continue for** }
   ...
}
}
}

repeat {
do {
for … {
   if … { break do }
   if … { continue repeat }
}

}
} while …

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

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


(Lily Ballard) #10

No it's not. The following compiles just fine (in Swift 2.1 and
Swift 2.2-dev):

repeat { do { break } } while true print("done")

But I don't think that's a problem. There's tons of precedent for
unlabelled break breaking out of the nearest enclosing loop rather than
the nearest enclosing scope. And people are generally going to learn
about unlabelled break before labelled break. The fact that you can
label a do {} and break out of it is interesting, but shouldn't change
the expected behavior of unlabelled break.

-Kevin Ballard

···

On Thu, Dec 10, 2015, at 11:05 AM, Austin Zheng via swift-evolution wrote:

Unlabeled "break" within a do is a compiler error, even if the do is
nested within a different control flow.


(Austin Zheng) #11

Indeed, you're right. If the do or if is nested within a loop the break works on the loop instead of the do/if.

Austin

···

On Dec 10, 2015, at 11:12 AM, Kevin Ballard via swift-evolution <swift-evolution@swift.org> wrote:

On Thu, Dec 10, 2015, at 11:05 AM, Austin Zheng via swift-evolution wrote:

Unlabeled "break" within a do is a compiler error, even if the do is nested within a different control flow.

No it's not. The following compiles just fine (in Swift 2.1 and Swift 2.2-dev):

repeat {
    do {
        break
    }
} while true
print("done")

But I don't think that's a problem. There's tons of precedent for unlabelled break breaking out of the nearest enclosing loop rather than the nearest enclosing scope. And people are generally going to learn about unlabelled break before labelled break. The fact that you can label a do {} and break out of it is interesting, but shouldn't change the expected behavior of unlabelled break.

-Kevin Ballard

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