DEV Community

Discussion on: 10 rules to code like NASA (applied to interpreted languages)

Collapse
 
andrewharpin profile image
Andrew Harpin

I respect Remy wishes to avoid the switch compilation, there are typically 2 outputs from the compiler, depending on the code and optimization settings:

  1. If else as mentioned, this is typically used when there are few options in the switch statement or there is a large Delta between the switch enumerals.

  2. Jump table if there are a large number of cases and they are mostly sequential the assembler can be a jump table where you have a start and the enumeral is an offset, this is more performance efficient, but not always space efficient and this is where your optimization settings come in.

There are edge cases which result in some quirky behaviour, but these are typically compiler specific