#93930 - 2002-09-30 07:10 PM
Re: An exact explination as to why goto's are bad
|
Radimus
Moderator
   
Registered: 2000-01-06
Posts: 5187
Loc: Tampa, FL
|
I'm certain there are very technical reasons they are bad, but the one that jumps out at me is that:
programs (and scripts) execute linearly... if the code execution has to jump around it is 'sloppy design', (Mr Morrison, 11th grade pascal instructor) and leads to difficulty it reading and modifying code. of course, sometimes a goto can't be avoided or make it easier...
That being said, CMD scripts are very weak, and you have no recourse, but to use GOTOs. as this is where most kix programmers start usually, it isn't unexpected that that programming style is used.
|
|
Top
|
|
|
|
#93933 - 2002-09-30 08:34 PM
Re: An exact explination as to why goto's are bad
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
I'm somewhat against the notion that having goto's in a script is a bad thing.
Generally speaking, most things that you can do with a goto, you can do with a loop, a function, or a subroutine. However, this is NOT always true. Sometimes, trying to get rid of your goto lines causes more problems. What comes to mind is when you need to exit a loop prior to some lines executing. In order to get around a goto to exit a loop, sometimes you must add additional conditions and comparisons. This can make the script MORE confusing rather than less confusing.
General rule:
Eliminate goto statements whenever possible to do so without increasing the complexity of the script.
Sure, this is a judgement call, but I would rather see a "GOTO" that makes sense than a funky loop that has weird conditions. Many of these "acceptable" uses of GOTO could be eliminated with statements like:
EXITFOR EXITDO EXITWHILE
Brian
|
|
Top
|
|
|
|
#93935 - 2002-09-30 08:49 PM
Re: An exact explination as to why goto's are bad
|
Kdyer
KiX Supporter
   
Registered: 2001-01-03
Posts: 6241
Loc: Tigard, OR
|
As a rule, we do not use GOTOs, but rather GOSUBs. The only time that we use a GOTO is when we want to go to a Sub-sub script and then return back to the main script..
Kent
|
|
Top
|
|
|
|
#93937 - 2002-09-30 10:47 PM
Re: An exact explination as to why goto's are bad
|
NTDOC
Administrator
   
Registered: 2000-07-28
Posts: 11634
Loc: Space
|
|
|
Top
|
|
|
|
#93940 - 2002-09-30 11:23 PM
Re: An exact explination as to why goto's are bad
|
BrianTX
Korg Regular
Registered: 2002-04-01
Posts: 895
|
Hee hee..
Yeah.. it actually runs FASTER without the goto.. I don't know how KiXtart implements gotos, but I found that the Do/Until was faster in this case... I think the While/Loop is faster for smaller segments of code... but it seemed slower in this function. I eeked out another percent or two of speed by changing it.
Brian
|
|
Top
|
|
|
|
Moderator: Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart
|
0 registered
and 2220 anonymous users online.
|
|
|