3 ms·
switch isn't 'invented' for enums. switch is a low-level construct which mimics several goto's / jumps. It's just as bad, except for the case where you have ei
by jbverschoor 4y ago
switch isn't 'invented' for enums. switch is a low-level construct which mimics several goto's / jumps. It's just as bad, except for the case where you have either: a) multiple behaviors for the same value, b) need to pass through (not break). b) is the nr 1 reason I hate switches, and my nr 2 reason is that most languages don't support proper enums, and will fail when you don't handle all possible values
- EVa5I7bHFq9mnYK 4y agoSwitch was invented because it allows to replace several ifs and gotos with a precomputed static jump table, an optimization trick.
- radiator 4y agoSwitch is not bad, far less is there any reason to hate it.
- smnplk 4y agoAgree. It's the same as saying don't use for loops or any other basic language constructs. Switch is very useful, please leave switch alone! You will not take switch away from me :)
- jbverschoor 4y agoWhen do you actually pass through? Only some state machines do that. But even I. That case, ifs are more clear and less error prone due to missing breaks, braces/scoping issues, etc