3 ms·
In lower level languages, when you use switch, you make it easier for the compiler to generate a jump table. In higher level langues with strong, static types,
by krapht 6y ago
In lower level languages, when you use switch, you make it easier for the compiler to generate a jump table.
In higher level langues with strong, static types, the switch statement can indicate to the compiler you want to match on the type of the variable; it can do analysis then to make sure your pattern match is exhaustive.
- lucideer 6y agoThese are good examples. Especially for a lower level languages this makes a lot of sense. For higher level languages, I would imagine typeguards would provide some of the desired functionality here, while being much more lightweight than a full alternative conditional syntax.