C's fall-through behavior is nice, in the sense that it has zero performance impact. It's simply what the CPU does under the hood by default. Nevertheless I'd want a keyword for that, and a jump behind the last case as the default behavior.
Putting the entire
case..end block into a
repeat..until False; block is quite silly - the only benefit is the indentation. A
goto is a much clearer sign of intent, but also feels unwieldy because you have to go to the top of the function and declare the label first...
Even worse is putting the entire
case..end block into its own subroutine (just so you can use
exit in a misguided attempt to avoid
goto), as it breaks the flow and impacts performance (FP likes to add SEH code everywhere) unless the subroutine is inlined. (But afaik the subroutine is always added to the compiled program even if
all calls to the subroutine are inlined, would love to know if that's wrong.)
case could be much better:
- an option to force the compiler to use a jump table (instead of repeated ifs)
- an option to skip checking if the selector is not one of the cases
- an option to terminate each case with a RET instruction for exiting the current subroutine instead of jumping behind the last case (RET uses the CPU's return stack buffer and doesn't pollute the branch predictor with unnecessary jumps)
- a way to reduce the jump table entries to smaller (16-bit or even 8-bit) displacements if the cases are close enough together
- a way to jump from one case to another case (determined by a value loaded at runtime) without going back to the top (would help the CPU's branch predictor because there's no longer a single dispatch point)
This would help a lot with making state machines (e.g. bytecode interpreters) faster...