On Mon, Oct 27, 2008 at 10:44 AM, David Hamill <[EMAIL PROTECTED]> wrote:
> - You have to remember to put in break statements, which are > really disguised gotos. http://kerneltrap.org/node/553/2131 $ Any if-statement is a goto. As are all structured loops. The whole page is worth reading if you've succumbed to the 'goto's are evil' brigade, however. > - Leaving out a break statement unintentionally causes a > bug, due to fall-through. It does happen, especially with > newcomers. Where-as leaving one out deliberately isn't a bug. Are you going to espouse compulsory braces in order that newbies don't fall into the if(foo()) bar(); baz(); trap? > - Omitting a break statement intentionally in order to fall > through to the next case is tricky and non-obvious code IMO. Not at all tricky, and once you've learnt the paradigm, totally obvious. > It can also lead to bugs if someone spots the "missing" > break and inserts it, or if the order of the cases is > changed for some reason, or if a new case is inserted. > Asking for trouble. Not if you put a comment in to the effect of /* follow through..*/ or /* no break */ at the end of the case. > - Switches test equality of integer values, whereas ifs can > test any requirement that can be reduced to a boolean > expression. Which is almost everything. That's a bad thing? > As for efficiency, if that were really important we'd all be > coding in assembler and using jump tables instead of > switches. If it were that important, then you'd be profiling your code and seeing what minuscule percentage of time your code was actually spending on the switch statement, and not bother with it. -- PJH http://shabbleland.myminicity.com/sec
