Page 1 of 1 1
Topic Options
#93929 - 2002-09-30 07:00 PM An exact explination as to why goto's are bad
h00kupz Offline
Fresh Scripter

Registered: 2002-07-17
Posts: 14
Loc: Atlanta
Just wondering because they seem to work great for login scripts so I wasn't sure if everyone's opinion (since it seems to be the opinion of everyone) is pertaining specifically to programming outside of a login script. I'm sure I'm mis-informed and goto's are probably bad for login scripts as well so let's hear it. [Confused]
_________________________
Select * from users where clue > 0 [b]0 rows affected.[/b]

Top
#93930 - 2002-09-30 07:10 PM Re: An exact explination as to why goto's are bad
Radimus Moderator Offline
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.
_________________________
How to ask questions the smart way <-----------> Before you ask

Top
#93931 - 2002-09-30 07:12 PM Re: An exact explination as to why goto's are bad
Shawn Administrator Offline
Administrator
*****

Registered: 1999-08-13
Posts: 8611
Think you'll find that the concensous is that GOTO's are frowned upon - not necessary a bad thing. Inside login scripts, its not sooo bad because one is normally just skipping over large chunks of code and "carrying forward" with a main logic flow.

But in a more complicated script ... with lots of loops and conditionals - goto's can really mess with your mind ... especially when folks try to use GOTO to GOTO places inside a loop - and they wonder why the logic breaks down. Much easier (imho) not to use gotos in these cases and spend (invest) the extra time (machine cycles) to work-out a non-goto solution.

Top
#93932 - 2002-09-30 07:53 PM Re: An exact explination as to why goto's are bad
Les Offline
KiX Master
*****

Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
Shawn,
Seems like a slight departure from this thread EH! [Big Grin]

Topic: Exit a While Loop
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.

Top
#93933 - 2002-09-30 08:34 PM Re: An exact explination as to why goto's are bad
BrianTX Offline
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
#93934 - 2002-09-30 08:47 PM Re: An exact explination as to why goto's are bad
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
I still haven't found any place where goto is actually needed.

brian, can you give some nice example which I might crack for you?
 
_________________________
!

download KiXnet

Top
#93935 - 2002-09-30 08:49 PM Re: An exact explination as to why goto's are bad
Kdyer Offline
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
_________________________
Utilize these resources:
UDFs (Full List)
KiXtart FAQ & How to's

Top
#93936 - 2002-09-30 08:51 PM Re: An exact explination as to why goto's are bad
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
kent, that is one place where it sounds acceptable with kix95.

with kix2k1 I can't see a reason for it either.
 

{edit}
added missing word "see"

[ 30. September 2002, 21:30: Message edited by: Lonkero ]
_________________________
!

download KiXnet

Top
#93937 - 2002-09-30 10:47 PM Re: An exact explination as to why goto's are bad
NTDOC Administrator Offline
Administrator
*****

Registered: 2000-07-28
Posts: 11634
Loc: Space
Lonkero... what about this thread?

Super-quick iterative quicksort!!!

http://www.kixtart.org/cgi-bin/ultimatebb.cgi?ubb=get_topic;f=2;t=003831

Top
#93938 - 2002-09-30 10:50 PM Re: An exact explination as to why goto's are bad
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
so, should I make it faster and without the goto's?

let me see...
 
_________________________
!

download KiXnet

Top
#93939 - 2002-09-30 11:06 PM Re: An exact explination as to why goto's are bad
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
don't need to anymore as brian did it already [Wink]

heh...

 
_________________________
!

download KiXnet

Top
#93940 - 2002-09-30 11:23 PM Re: An exact explination as to why goto's are bad
BrianTX Offline
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
#93941 - 2002-09-30 11:30 PM Re: An exact explination as to why goto's are bad
Lonkero Administrator Offline
KiX Master Guru
*****

Registered: 2001-06-05
Posts: 22346
Loc: OK
again, only reason for using goto as speed advantage is to skip some 5000 lines of code, but then, who has that amount of lines being set one after another?
there probably is some sort of selection...

so, after all, there is no usage for goto.
it's just a command for compability with minds learned to think in the old way and using simple syntax.
_________________________
!

download KiXnet

Top
Page 1 of 1 1


Moderator:  Arend_, Allen, Jochen, Radimus, Glenn Barnas, ShaneEP, Ruud van Velsen, Mart 
Hop to:
Shout Box

Who's Online
0 registered and 2220 anonymous users online.
Newest Members
Viginette, ManuvdWielNL, Sir_Barrington, batdk82, StuTheCoder
17888 Registered Users

Generated in 0.074 seconds in which 0.036 seconds were spent on a total of 12 queries. Zlib compression enabled.

Search the board with:
superb Board Search
or try with google:
Google
Web kixtart.org