in reply to GOTO or not GOTO
The main problem with goto is not understanding potential side-effects. If you goto a particular location then you run the risk of using code that assumes a different state to the one you arrive in.
My issue with goto has always been the stack - I will (albeit rarely) use goto if it does not involving changing contexts (i.e. never jumping into or out of a set of curly braces). But I really don't know the implications to memory usage and contexts when I do something like the following (in C or in Perl):
for ( my $i = 0; $i < 10; $i++ ) { my $j = $i; if ( $i == 5 ) { goto newlocation; } } newlocation: print( "jumped out" );
Now my question is what happened to $j there? Is the compiler "smart enough" to know that I exited the loop and therefore the memory allocated to $j can now be reclaimed?
Even worse, what happens when I use goto to jump between subroutines?
It is because I don't know the answers to these questions that I do my best to avoid the use of goto (except when necessary and not involving context changes).
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: GOTO or not GOTO
by ikegami (Patriarch) on Jan 27, 2009 at 07:06 UTC | |
Re^2: GOTO or not GOTO
by JavaFan (Canon) on Jan 27, 2009 at 08:17 UTC | |
by monarch (Priest) on Jan 27, 2009 at 12:24 UTC | |
by JavaFan (Canon) on Jan 27, 2009 at 12:37 UTC |