> From: "Brian Goetz" <brian.go...@oracle.com> > To: "Guy Steele" <guy.ste...@oracle.com>, "Remi Forax" <fo...@univ-mlv.fr> > Cc: "amber-spec-experts" <amber-spec-experts@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