Reviewing feedback on patterns in switch
forax at univ-mlv.fr
forax at univ-mlv.fr
Wed Feb 16 16:03:14 UTC 2022
> From: "Brian Goetz" <brian.goetz at oracle.com>
> To: "Guy Steele" <guy.steele at oracle.com>, "Remi Forax" <forax at univ-mlv.fr>
> Cc: "amber-spec-experts" <amber-spec-experts at openjdk.java.net>
> Sent: Wednesday, February 16, 2022 4:05:35 PM
> Subject: Re: Reviewing feedback on patterns in switch
>>> 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.
And also the if stis followed by parenthesis and there is no need of parenthesis for a guard.
So either people will always put parenthesis after if as a guard or be mystify that parenthesis are not required for a guard but required for the if statement.
Rémi
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/amber-spec-experts/attachments/20220216/b25f7ab4/attachment-0001.htm>
More information about the amber-spec-experts
mailing list