On 05.11.19 08:39, Daniel.Sun wrote:
Hi Rémi,
Thanks for your detailed explaining. Switch expression is useful in
some cases, but fallthrough is error prone. I seldom use switch statement,
in the past, I widely used it when I wrote lexer/parser by hand. I prefer to
use if-else instead, which is much more powerful.
In Groovy I actually used it a lot. In Java the statement is too
limited. But I have doubts that it will become popular in the new form
without pattern matching. The question I have to you all here is
actually if you think the switch statement will come without the pattern
matching. For example will they fix the syntax on this without having
fixed the syntax for pattern matching to have to use the switch expression?
Though devil exists in some shapes of switch expression, Groovy may
have to support all shapes for compatibility with Java.
Do we really? If we really want to support it, we should support its
use-case, which is a Lexer. Writing an efficient lexer in Groovy would
be way off with switch expressions, because of the transformation to
Closure and the overhead it involves.
Pattern matching is a lot more than just lexer though... but with
algebraic types I wonder how far we can really go. At least if you want
the compiler to be able warn you about missing cases and such.
bye Jochen