Expression switch feedback

David Lloyd david.lloyd at redhat.com
Mon Apr 9 21:03:06 UTC 2018


On Sun, Apr 8, 2018 at 9:49 AM, Brian Goetz <brian.goetz at oracle.com> wrote:
> Could we fix this now?  Well, we could start now.  We could introduce a
> `fallthrough` statement, and maybe warn when you fell through without it (we
> actually have a lint warning for this now.) Over time, we could make falling
> through without saying `fallthrough` an error.  Over a much greater period
> of time, we could _maybe_ consider inferring break when you hit a case
> statement, if we were confident that every program that fell through without
> saying `fallthrough` had been recompiled and fixed, and all programmers
> suitably reeducated.

I will humbly submit that it would be nifty (for me at least) to have
an explicit:

   goto case "Foo"; // and
   goto default;

statement (as a generalization of, and alternative to, fallthrough),
whose use could be first suggested by IDEs, and maybe later enforced
by later versions of the language itself in lieu of implicit
fallthrough.  That would be so nice for state machines (including
parsers and network protocol processors, among many many other
things), of which I seem to write about one every other week.  To my
naive mind, translation of such a thing seems like it should be
approximately as complex as that of "break".

That is all; I shall now hide in the corner.

-- 
- DML


More information about the amber-dev mailing list