🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.misc
Article #4379

Re: GOTO controversy

#4379
From: John Noland
Date: Thu, 07 Mar 1996 21:00
50 lines
2661 bytes
In article <4hlg11$dd7@news1.mnsinc.com>, huang@mnsinc.com says...
>
>John Noland (sinan@cyberramp.net) wrote:
>
>[snip]
>:  DON'T use a goto unless it's the only solution to the problem.
>:  You have many alternatives to a goto in your above code. 
>
>Wrong.  'goto' will never be the only solution.  When the 'goto'
>solution is more elegant than the other choices (which is entirely
>possible), use 'goto'.
>

These are guidelines, not hard and fast rules. But, you're right, if this
were true, then the situation I presented of breaking out of a nested loop
would break this since there is an alternative. I probably should have
worded that differently. Your response is better.

>:  A subroutine should have at most one label.
>
>Arbitrary number.  Does a subroutine with exactly *two* labels
>automatically and magically become unreadable?
>
>:  All goto's should be above that label in the code.
>
>Above?  You mean all 'goto's should be forward jumps?  Why?
>

The reason for these two is to develop a mindset. If I stray from these, I
want the thought "Am I f***ing up here!" in my head. Using goto's
can lead to a lazy attitude, which can lead to abuse. I currently maintain
a huge set of COBOL code that is littered with goto's in every direction.
Believe me, it's a bitch to make changes to this code and when I jump into
it, it becomes real easy to say f*** it and do the same thing myself. If I
let this attitude creep into my C programming I'd be a dead man. I
advocate the judicious use of goto's. If I had to list one hard and fast
rule it would be, keep the goto's and their labels in the same block of 
execution. Have a little mercy on yourself and/or the person following you
in the future. 

>That's the point against using 'goto's.  Realize however that a
>good engineer is usually smarter than blind guidelines.  The
>rules you raised have obvious drawbacks.  Personally, the rule
>I impose upon myself is: "If you use a 'goto', you better have
>a damn good reason for it and be prepared to explain why all
>other constructs make the program uglier."

Well said! 

-John
Technical Details
Message-ID: <4hnioo$jbb@newshost.cyberramp.net>
Path: arc1-ca.pugleaf.net!newshost.cyberramp.net!news
References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!newshost.cyberramp.net!news
From: sinan@cyberramp.net (John Noland)
Newsgroups: comp.lang.misc,comp.lang.c,comp.lang.pl1
Subject: Re: GOTO controversy
Date: 7 Mar 1996 21:00:08 GMT
Organization: Prose Software
Message-ID: <4hnioo$jbb@newshost.cyberramp.net>
References: <rcshlds.1.000A6705@mailserv.mta.ca> <Dn8pJ8.nqs@emi.net> <4grt4e$8fg@goanna.cs.rmit.EDU.AU> <4hl8mt$4po@newshost.cyberramp.net> <4hlg11$dd7@news1.mnsinc.com>
NNTP-Posting-Host: ramp2-13.cyberramp.net
X-Newsreader: WinVN 0.99.5