5 ms·
Switch should be the new Goto
- timrobinson 16y ago> With proper sub-typing the implementation of the current execution path should be easier to read I'm not sure how the existence of virtual functions makes the execution path easier to read...
- bhousel 16y agoMaybe "extreme over-architectured OOP" should be the new Goto.
- astrodust 16y agoIf you're subclassing to dodge a simple switch you're in serious trouble.
- maratd 16y agoErrrr.... NO. The problem with goto is that it breaks the execution flow. Switch doesn't do that. A switch statement is much easier to understand than an army of if statements. Aside from personal conjectures, there isn't a single argument provided against a construct that is found in every modern programming language.
- dko 16y agoIt all boils down to the context that switch is used. And with the growing popularity of loosely typed languages, it's probably not a good idea to make such sweeping statements.
- nathanlaan 16y agoAgreed. There are likely cases where using a switch statement is not the optimal approah, but IMO saying that you should never use it over-generalizes.
- ENOTTY 16y agoGoto isn't completely bad. It's used all over the FreeBSD kernel to bail out in error conditions.