3 ms·
I always thought the urge to replace switches with objects was fashionably bad advice. I get that the object literal approach feels more functional, and that f
by your-nanny 7y ago
I always thought the urge to replace switches with objects was fashionably bad advice.
I get that the object literal approach feels more functional, and that forgotten break statements will cause havoc tho.
Seems like a safeswitch construct is in order, that does not allow dropthrough. something like:
safeswitch(s) {
case 'alpha':
calc(alpha(x), 2);
case 'beta':
calc(beta(x), beta(x*x));
} else {
// default case here
calc(x);
}
alternatively, switch could be modified so that passthrough is not the default, and so, instead of a break statement one would use a passthrough statement to enable that behavior (opt in instead of opt out)