[Coco] GOTO and code maintainability

Gene Heskett gene.heskett at verizon.net
Tue Sep 8 22:25:35 EDT 2009

On Tuesday 08 September 2009, Aaron Banerjee wrote:
>On Sep 8, 2009, at 8:15 PM, Lothan wrote:
>> I think Gene brings up an excellent point regarding the complexity
>> of maintaining stack state with GOTOs, though. In general, you ought
>> to avoid jumping into the middle of a code block if possible... but
>> not to a religious extreme if it can't be helped. Just keep in mind
>> that jumping into the middle of nested code blocks (if, for, while,
>> do, loop, switch, ...) mucks with the stack and may cause some
>> amount of unpleasantness at run-time. Some languages (notably C#)
>> avoid this complexity by explicitly prohibiting jumping from one
>> code block to another; e.g. labels in C# are scoped to the code
>> block they're in.
>Maintaining the stack is most certainly an important issue.  Several
>years ago, I wrote a program to solve the "Eight Queens" problem on a
>coco.  I counted on the fact that you could "jump out of" a for/next,
>alter the counter, and jump back in order to simulate recursion.  That
>program was more of an academic curiosity, and most certainly not
>intended to promote jumping in and out of FOR loops.  It ran on ECB
>1.0, but not on GWBASIC.
>I think the resounding issue of this thread is that even GOTO can be a
>good thing if used appropriately, just as almost anything can be "bad"
>if misused.
>              - Aaron

This is one of those cases where that Clint Eastwood quote fits.  A man must 
know his (C compilers) limits.  :-)

Cheers, Gene
"There are four boxes to be used in defense of liberty:
 soap, ballot, jury, and ammo. Please use in that order."
-Ed Howdershelt (Author)
The NRA is offering FREE Associate memberships to anyone who wants them.

C makes it easy for you to shoot yourself in the foot.  C++ makes that
harder, but when you do, it blows away your whole leg.
		-- Bjarne Stroustrup

More information about the Coco mailing list