Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number

Re^2: Number of times I've used goto in Perl

by Anonymous Monk
on Jun 16, 2009 at 21:37 UTC ( #772148=note: print w/replies, xml ) Need Help??

in reply to Re: Number of times I've used goto in Perl
in thread Number of times I've used goto in Perl

I quite agree. The first language I ever learned was a rather primitive dialect of BASIC. There were no block IF statements, no NEXT, LAST, CONTINUE etc for while loops. The only branch commands were GOTO and GOSUB. One can write very clear, very well-structured code with GOTOs. However, the structure must be self-imposed since the language will not force you to write in a well-structured fashion. Saying that GOTO causes messy code is like saying that hammers cause squashed thumbs.

The best description I have heard is that GOTO is like a stick of dynamite. Occasionally, when programming, you come across a large boulder in the middle of your path. While you *can* build an elaborate structure to go around it, it is often faster and more efficient to just blow it up. Just be careful not to bury yourself under tons of rubble when doing so.

The other place to use a goto is anyplace you find yourself intentionally building an infinite loop. If you use a while(1) kind of construct, you are necessarily wasting CPU cycles evaluating a conditional which is always true. Building such a loop with GOTOs is just as easily readable, and more efficient.
  • Comment on Re^2: Number of times I've used goto in Perl

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://772148]
[LanX]: Socrates was a Troll
[Your Mother]: It's very, very dangerous... Thinking that a group is intrinsically evil... buries the fact that all humans can be so deep that it starts to become likely they will be.
[Your Mother]: LanX++
[Corion]: (also the "troll for trolls sake" could seen be much like the "punk for punks beer")
[Your Mother]: I'm completely (historically anyway) a troll in real life. It's not fun online, you can't really win. :P
Happy-the-monk orders a Punk IPA.
[Your Mother]: Also, I'm too old to start fights with strangers anymore.
[LanX]: concentrating on omestic violence?
[LanX]: d
[Your Mother]: Open air violence. Or on campus.

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (22)
As of 2018-03-19 13:47 GMT
Find Nodes?
    Voting Booth?
    When I think of a mole I think of:

    Results (240 votes). Check out past polls.