|
|
|
|
|
by vortico
2264 days ago
|
|
Just a reminder that in most compiled and JIT optimized languages with switches, this switch (c) {
case 4: return 30;
case 5: return 70;
default: return 0;
}
compiles to the same instructions and therefore same performance as if (c == 4) {
return 30;
}
else if (c == 5) {
return 70;
}
else {
return 0;
}
As a side note, it's easier to see accidental fallthroughs if you write switch statements like this. switch (c) {
case 4: {
return 30;
} break;
case 5: {
return 70;
} break;
default: {
return 0;
} break;
But in my opinion, the `if` statement is more clear in both cases, and only one level of indentation instead of 2. |
|
Eye of the beholder, indeed.