The EVIL goto...
-----------------------------
A wise man once said "A person with half a clue is more dangerous than a person with or without one."
-------------------------
-Programmers don't byte, they nibble a bit.
Unknown Person
-------------------------
The reason goto was included is for those situations in which you absolutely have to have it, and since C is a systems programming language, there are instances when writing say an OS kernel in which goto has its uses.
goto is not evil in and of itself, but as a programmer who spent a few years(in 80''s) writing BASIC code, I will say that goto''s produce code which is unreadable after a certain size. Gosub(from BASIC) isn''t much better. Functions accomplish many of the same purposes, but encourage reuse and reduce causes for errors(like inadvertently changing a variable used by the code the goto''d the current code). if''s/ do''s/ while''s/ for''s/ function''s/ and switch''s will accomplish everything goto does but will make your life easier in 3 months when you come back to look at it. This is experience talking, not computer science, and just be glad you don''t have to use line numbers(one renum and you''re spending HOURS figuring out where sections of code are).
My CS prof hit me when I told him.
Essentially, people are so opposed to goto because there really is no reason for it to be used. You can do anything you want with other constructs, particularily functions. If you have a bunch of nested loops or something, look for a cleaner way to cut out of them. You''ll love yourself later.
It has the potential to be abused much more than other statements; by inexperienced programmers and those who come from BASIC (or similar) backgrounds, goto does get abused.
But the occassional and proper use of goto can make code readable and easy to maintain over using other sorts of control structures.
However, I find the need to use goto is very infrequent. Also keep in mind that while every ANSI C conforming compiler supports it, not all support it well. Because of the bad rap it has gotten and the infrequency of its use, various compilers will either botch the generated code or optimize it poorly. That in itself may be a reason to avoid or minimize using goto .
---- --- -- -
Blue programmer needs food badly. Blue programmer is about to die!
quote: Original post by mossmoss
...those who come from BASIC (or similar) backgrounds, goto does get abused.
yep, that''s the case. We don''t want to show that we started with *laaaaame* basic
pi~
btw what''s a blue programmer?
Because it can be bad and isn''t absolutely necessary to programming, most people thing it is a bad idea.
So next time someone tells you that goto is Evil(TM), ask them if they approve of exception handling. If they say yes, just sit back and smile.
Oh, and if that isn''t convincing enough, answer this: what is the one statement in C or any other language that compiles to a *SINGLE* instruction on just about every chip known to mankind? Call it JMP, BRA, or whatever, it''s still GOTO to me
--Capt. Mathew Neville
IMHO, goto is one of those tools that is more liable to do damage than good. New programmers should stay away from goto while they get experience. Then once you have a good understanding of real world programming, then goto can be used effectively.
I once was talking to someone who had a masters in music. He said that when getting your bachelors (sp?), you learn all the rules to making music. When getting your masters, you learn how to break those rules. I think of goto the same way, you must first learn the rules of structured programming before you can really understand when to use goto.
Tim