Implicit case fall-through considered harmful

# David-Sarah Hopwood (17 years ago)

Brendan Eich wrote:

On Oct 27, 2008, at 8:21 AM, Maciej Stachowiak wrote:

A more functional multiple-case dispatch form would be like Scheme's cond' or ML/Haskellcase'. God, we need macros.

ECMAScript's switch is sort of halfway between Scheme cond and C switch. Personally I think fall through and explicit break were unnecessary concessions to C-likeness but I don't think they create insurmountable problems. Case labels at arbitrary points in the code would be much worse because it's hard to describe them in any way but a controlled goto.

Netscape management said that JS had to "look like Java", which follows C in having fall-through from an upper case to a lower one. Same as C++. That's a big head-wind to tack against, and I was not prepared to explain yet another switch statement to Java-heads circa 1995.

Cyclone and Jacaranda require fall-through to be marked with an explicit 'fallthru' token. I've use this convention for years in C, and find that it does help even when not enforced by a compiler.

For Cyclone, see the first item of 'Restrictions' in cyclone.thelanguage.org/wiki/Switch Statements.

For Jacaranda, this token is spelled as a comment for compatibility, and is specified as follows:

Each <CaseClause> or <DefaultClause> in a switch statement MUST: - have no statements, or - end with a /fallthru/ token, or - end with a <ContinueStatement>, <BreakStatement>, <ReturnStatement>, or <ThrowStatement>, or - be the last clause.

The last clause in a switch statement MUST NOT end with a /fallthru/ token.