Beefy Boxes and Bandwidth Generously Provided by pair Networks
Think about Loose Coupling
 
PerlMonks  

"Appropriate" use of goto (was RE: Re: Minor query)

by spudzeppelin (Pilgrim)
on Jun 24, 2000 at 01:38 UTC ( [id://19674]=note: print w/replies, xml ) Need Help??


in reply to RE: Re: Minor query
in thread Minor querry!!

I beg to differ. "Never, never, never use goto!" is one of those programming mantras which are taught to beginners because at that level, the temptation is to use it where it is not appropriate. However, as a developer becomes more experienced, the usefulness, clarity, and simplicity of an unencumbered "jump over there" instruction make it more valuable when used sparingly and appropriately. And in this case, an exception handler of a sort that basically says "go back three lines and try it again," the use is very appropriate.

While we are drifing dangerously offtopic, I am going to ask you to reconsider the two snippets above, and tell me which is actually more readable -- the one that obfuscates a goto with a while loop, or the one that explicity uses the goto when the goto is EXACTLY the instruction being used in both, algorithmically.

Spud Zeppelin * spud@spudzeppelin.com

  • Comment on "Appropriate" use of goto (was RE: Re: Minor query)

Replies are listed 'Best First'.
RE: goto?
by Aighearach (Initiate) on Jun 24, 2000 at 15:50 UTC

    as St. Larry once said,

    If I allowed "next $label" then I'd also have to allow "goto $label", and I don't think you really want that... :-)
    -- Larry Wall

    Of course both were in fact added, but you can clearly see the concern expressed over "goto." The worst thing about goto is that those of us who spent our teenage years writting spaghetti in BASIC that consisted of 30% GOTO will be so frightened and appalled at the sight of it, that we will run screaming in the other direction. Proabably not the response you want your code to get...

    Paris Sinclair    |    4a75737420416e6f74686572
    pariss@efn.org    |    205065726c204861636b6572
    I wear my Geek Code on my finger.
    
RE: use of goto
by Adam (Vicar) on Jun 24, 2000 at 01:54 UTC
    While they may be identical algorithmically, I find the while() loop preferable for two reasons.
    1. It is more readable (sorry spud. It is. Deal with it.)
    2. It is more maintainable (A clearly marked block is always preferable.)

    But of course, I think goto has its place, and should occaisonally be used. If you think about it, at the assembly level, goto is the only looping mechanism available. And of course, TIMTOWTDI.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found