|
|
|
|
|
by marcus_holmes
2264 days ago
|
|
Switch statements indicate "it's one of these things", whereas in the series of ifs any of them could be true. Using a switch statement tells the reader that you expect one of these things to happen [0]. Using a series of ifs tells the reader that these things might or might not happen depending, and they're going to have to read each statement to work out which. Your last version doesn't tell the reader what your intention is at all, and they need to work out what you're trying to do here. It's a lot less readable. Unless you're desperate for those bytes, it'd be better to use the switch statement for this case. [0]: This gets a little weird in languages like JS where switch statements fall through to the next one if you don't break or return, but generally it still holds true. |
|