Loop iterator - example.txt

kris foo at bar.com
Sun Apr 30 20:23:46 PDT 2006


Walter Bright wrote:
> Derek Parnell wrote:
> 
>> The use of 'goto' has an inherinent cost in terms of ongoing 
>> maintenance of code. In short, it adds to the time it takes to analyse 
>> code prior to making changes that do not have unintended side-effects. 
>> That cost must be justifed. Therefore one should only use 'goto' in 
>> situation in which the cost of its use can be offset by some other 
>> gain in the code. Such a gain is performance in a performace-critical 
>> section of code. I'm not sure if there are any other situations it is 
>> cost-justified.
> 
> 
> A goto is also useful:
> 
> 1) to avoid excessive diffs caused by refactoring code
> 
> 2) when one wants to build a control structure that just doesn't fit 
> into the usual if-else, while, for, etc.
> 
> 3) to avoid the creation of silly 'flag' state variables
> 
> 4) to create an efficient state machine
> 
> 5) as output from program generators
> 
> 6) to, for instance, collect all error handling code in one spot in a 
> function


#4 is definately useful within a switch(){}

Alternate design strategies aside, I was always told that goto, in 
general, lead to *less* efficient code. Didn't compilers (perhaps in the 
past) disable the optimizer for functions with one or more instances of 
goto? Doesn't it mess with flow analysis, or something?



More information about the Digitalmars-d mailing list