Yield as contextual keyword (was: Call for bikeshed -- break replacement in expression switch)
forax at univ-mlv.fr
Tue May 21 06:05:42 UTC 2019
----- Mail original -----
> De: "John Rose" <john.r.rose at oracle.com>
> À: "Brian Goetz" <brian.goetz at oracle.com>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Envoyé: Lundi 20 Mai 2019 22:00:43
> Objet: Re: Yield as contextual keyword (was: Call for bikeshed -- break replacement in expression switch)
> On May 20, 2019, at 12:51 PM, Brian Goetz <brian.goetz at oracle.com> wrote:
>> The cost-benefit analysis rests on the assumption that this will bite
>> exceedingly rarely, and when it does, the workaround will be clear and easy.
> OK, so let's road-test "yield".
> While "break: x" is syntactically safer than "yield x", I buy
> your argument. And "yield x" is easier to explain to users.
> We all know why ":" is necessary in "break: x" but users
> will need explanations about the colon where "yield x"
> will just work for them.
> There's always a trade-off between precision and
> concision. Concise formulations are inherently
> ambiguous, just because there are a limited number
> of length-N strings and each can be given only one
> semantic pigeonhole. Adding a new keyword
> lets us occupy new pigeonholes with the same
> number of tokens.
> So, while "break: x" would please me as a syntax
> geek, "yield x" (if it really works) will please me
> as a user. We should try it if we think we can
> make it work.
I think we should not neglect the fact that a lot of Java users don't like the keyword break because for them it embodies the fallthrough problem of the switch statement syntax.
So reusing break even with a colon after it goes in the wrong direction in term of a syntax signalling the semantics we want.
This argument is also why yield is better keyword than break-with.
> — John
More information about the amber-spec-observers