[Coco] GOTO and code maintainability

Aaron Banerjee spam_proof at verizon.net
Tue Sep 8 21:59:04 EDT 2009

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

More information about the Coco mailing list