Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?

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

by Casteele (Novice)
on Jun 04, 2016 at 00:52 UTC ( #1164906=note: print w/replies, xml ) Need Help??

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

There needs to be an answer for "As often/little as needed (but not more or less...)." IMO, "goto" is just another tool in a Perl programmers toolbox. It should be used when/where it's appropriate, and not when it's not.

Having been writing programs since the early 80's, i remember when the whole concept of "goto is evil" arose, not because of goto itself, but because of how many times code would become hard to follow and read (referred to as "spaghetti code"). These days, I do not see that kind of code much, but I do see code which some programmers do all kinds of hard to read/follow "tricks", *just* to avoid the use of goto. This makes no sense to me given the whole concept of "avoid goto" arose from the idea that such code was hard to read/follow. Why does making the code hard to read/follow at the *other* extreme make such code "better?" It doesn't.

When you develop in assembly language, for example, it's nearly impossible to avoid the use of jump/branch statements (upon which goto is based/modeled) in non-trivial code, and still write code which is fast and small--and yes, easy to follow. To do the same thing without any form of branch/jump/"goto", would require a lot of extra confusing code, or the use of many more subroutines ..and the extra overhead of calling them! It's faster and less code to simply change the current execution address than it is to.. save the registers/flags/call data/other state data, allocated stack space, transfer to a new routine, load the data back, process it, save it all back again, return from the routine, restore everything again, and resume execution. Sounds like a complicated mess like that? It is!

This whole issue, to me, is similar to the issue of code comments/documentation. I've seen far more people who do not comment/document--or just as bad, people who add comments when they're not necessary because the code is already self-evident.

IMO, we need less people preaching "Never use 'goto'!" and more people preaching "Program intelligently; Use what you need and keep it clean, simple, and understandable."

  • Comment on Re: Number of times I've used goto in Perl

Replies are listed 'Best First'.
Re^2: Number of times I've used goto in Perl
by BrowserUk (Pope) on Jun 04, 2016 at 04:29 UTC
    Program intelligently;

    I wholeheartedly agree.

    Unfortunately there is a large and apparently growing section of the (IT) community that seem to want be able to program by rote; to mechanically follow a recipe, a set of rules followed verbatim: stand up and say "Yay!" for 5 minutes; sit down and write 10 minutes of non-production code; swap seats and write 5 minutes of production code; 20 minutes of watching "XYZ passed" scroll up the screen. Rinse and repeat until the end of the day.

    New day, 5 minutes standing. "What did you do yesterday?". "I wrote 13 new tests". {collective} "Yay!".

    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority". I knew I was on the right track :)
    In the absence of evidence, opinion is indistinguishable from prejudice. Not understood.

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2019-10-23 17:44 GMT
Find Nodes?
    Voting Booth?