[Coco] GOTO and code maintainability

Gene Heskett gene.heskett at verizon.net
Mon Sep 7 22:25:00 EDT 2009

On Monday 07 September 2009, Aaron Banerjee wrote:
>All of us have at least at one point in time either used, or tried to
>figure out code containing GOTO statements.  In a recent programming
>environment I was in, GOTO (or it's equivalent in whatever language we
>happened to be programming) was expressly forbidden -- no exceptions
>no matter what.
>Just to be an irritant, I chucked a single GOTO (to make a polling
>loop) in a relatively simple program, which totally confused my
>Given that it isn't abused, I don't see why GOTO makes code any less
>maintainable than other obviscation techniques, such as polymorphism
>(which, while useful, if abused can lead to very multiple inheritance
>or exception-based program control.  At least GOTO tells you where it
>is going....
>Has anyone else run into this type of "GOTO intolerance" while
>                           - Aaron

The largest reason to discourage its use is because then the compiler must 
use even more resources tracking the stack.  


Your proggy is well and truly into a stack of subroutines possibly 10 deep on 
the stack and encounters a goto.  At this point the compiler can either 
upchuck and make you take it out, or it can search through a table to find 
the stack offset in effect now, then backtrack far enough in front of the 
goto's target label and try to figure out what the stack offset would be if 
it approached that target label by some other sequence of events, then insert 
enough stack cleanup in the goto path to keep the stack sane.  Without that 
effort, the first return it encounters, which will pull the address it is to 
resume execution at off the stack, there is an excellent chance of that 
return becoming a bushel of colored confetti on the screen crash.

I have had both crashes, and good results using goto's in C.  B09 seems to 
have a little better control,  but I have also had an on err goto go up in 
smoke with basic09.  Probably because the stack pointer wasn't tracked well 

Interpreted languages such as the basic in the roms, generally fare better in 
that dept.
>Coco mailing list
>Coco at maltedmedia.com

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.

Oh, wait, that was Randal...nevermind...
             -- Larry Wall in <199709261754.KAA23761 at wall.org>

More information about the Coco mailing list