|
|
|
|
|
by vortico
2264 days ago
|
|
Looks the same to me. https://godbolt.org/z/CfhD5k Switches were invented mostly because they were an easy hint to the compiler to reduce to a tree search, but because compilers are smart today, they're obsolete unless you just prefer their syntax. Even if the cases are consecutive, most compiler optimizers are smart enough to determine that the ASTs are equivalent. |
|
This is a good point.
Sometimes I prefer the (ugly) syntax of switches than that of conditionals. The reason is that a chain of conditionals is non-symmetrical (there's no condition for the first "case"), while a switch is formally invariant to permutation of the cases. I have even seen shit like this:
just to preserve the symmetry along the cases.