Problems? Is your data what you think it is? | |
PerlMonks |
Re^5: fall through switch/case in perlby radiantmatrix (Parson) |
on Sep 07, 2004 at 18:21 UTC ( [id://389161]=note: print w/replies, xml ) | Need Help?? |
You mean, people should rethink good code?
Well, yes. But that's not the point, exactly. Using switch statements doesn't automatically make bad code; however, this thread alone shows several ways to accomplish the same task without using a switch. Some of those ways are actually better than using a switch. Summary: always rethink good code, as long as you think it can be better. Just stating "switch statements are unbelievably over-used" does not make correctness either. Back up your claim. You do realize these are my opinions, right? That said, I repeatedly see programmers use switch syntax in odd places. When I ask them why they did it, the usual reply is "it was easiest". Switches are used (typically) to evaluate what might otherwise be a big chain of if/else/.../elsif statements. There are (obviously) other ways to accomplish that task, but that's not really important. The important bit is that there really aren't that many occasions for that level of nested if/else checking, and my personal experience shows that rethinking an algorithm requiring a switch almost always results in a better algorithm. Then again, as I've said before, there are cases where it really is the only reasonable way to approach a problem. Really, there is no need to assume that a statement of opinion is some kind of programmig law. I'm merely an acolyte, for cripe's sake: why on earth are you taking anything I say so seriously?
-- $me = rand($hacker{perl});
In Section
Seekers of Perl Wisdom
|
|