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 reply to Re^5: fall through switch/case in perl by radiantmatrix
in thread fall through switch/case in perl by ykar

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.