Reviewing feedback on patterns in switch
Brian Goetz
brian.goetz at oracle.com
Wed Feb 16 15:05:35 UTC 2022
>>
>> For me, && is more natural than "when" because i've written more
>> switch that uses && than "when".
>> And don't forget that unlike most of the code, with pattern matching
>> the number of characters does matter, this is more similar to
>> lambdas, if what you write is too verbose, you will not write it.
>
> At the risk of premature bikeshedding, have we already discussed and
> discarded the idea of spelling “when” as “if”? It’s been a long time,
> and I forget.
There was not extensive discussion on this, and its all very
subjective/handwavy/"what we think people would think", but I remember a
few comments on this:
- The generality of "if" reminded people of the Perl-style "statement
unless condition" postfix convention, and that people might see it as an
"inconsistency" that they could not then say
x = 3 if (condition);
which is definitely somewhere we don't want to go.
- We're use to seeing "if" with a consequence, and a "naked" if might
have the effect of "lookahead pollution" in our mental parsers.
- Keeping `if` for statements allows us to keep the "body" of case
clauses visually distinct from the "envelope":
case Foo(var x)
if (x > 3) : if (x > 10) { ... }
would make people's eyes go buggy. One could argue that "when" is not
fantastically better:
case Foo(var x)
when (x > 3) : if (x > 10) { ... }
but it doesn't take quite as long to de-bug oneself in that case.
On 2/15/2022 9:55 PM, Guy Steele wrote:
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220216/7948b380/attachment.htm>
More information about the amber-spec-experts
mailing list