Loop iterator - example.txt

Walter Bright newshound at digitalmars.com
Sun Apr 30 20:06:34 PDT 2006


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



More information about the Digitalmars-d mailing list