Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^4: fall through switch/case in perl

by Anonymous Monk
on Sep 07, 2004 at 15:59 UTC ( [id://389116]=note: print w/replies, xml ) Need Help??


in reply to Re^3: fall through switch/case in perl
in thread fall through switch/case in perl

I never said switch was bad code.

You mean, people should rethink good code?

As to your "considering many languages have a 'switch'", multiplicity does not correctness make.

No, but it does mean your bold statement needs at least a shred of backup. Just stating "switch statements are unbelievably over-used" does not make correctness either. Back up your claim.

Replies are listed 'Best First'.
Re^5: fall through switch/case in perl
by radiantmatrix (Parson) on Sep 07, 2004 at 18:21 UTC
    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});

      I'm merely an acolyte, for cripe's sake: why on earth are you taking anything I say so seriously?

      Because XP doesnt mean anything. TimToady is "just" an abbot. We listened to him before he was even an acolyte, when he was an acolyte and afterwards.

      Anyway, I dont know how the AM got the wrong side of the points you were making, but they sounded to me like there was some truth in what you say. Especially as "switch" in C only handles integers.


      ---
      demerphq

        First they ignore you, then they laugh at you, then they fight you, then you win.
        -- Gandhi

        Flux8


      So, we should dismiss anything you say as just an opinion? Postings that don't make clear what are facts and what are opinions are worthless.
        *sigh*

        You are really too angry. If you were near me, I'd buy you a beer.

        Yes, when anyone says "You are better off doing this", it is opinion. It might be supported by facts, but it is still opinion. I welcome any who disagree with something I say to point out why I am wrong - this is how I learn more.

        Besides that, it is far more effective to follow the traditional debate format. "I think" is assumed. If you disagree, please explain why so we can have a useful debate on the matter.

        That is far more useful and productive than the effective "Nuh uh!" I've been getting.

        --
        $me = rand($hacker{perl});

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://389116]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-04-18 16:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found