Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

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]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2017-04-30 04:19 GMT
Find Nodes?
    Voting Booth?
    I'm a fool:

    Results (534 votes). Check out past polls.