Goto statement - The problem?
Now, i read everywhere about many people having a problem with the use of the goto statement (Java even removed it from their language to avoid the use of it - If i'm not mistaken? :tongue:)
But my question is - Why all the bad publicity for it? Goto statements are generally useful in the odd ocassion!
I also have another quick question - In regard to performance issues would it be quicker to do for example
Code:
If (Value == Value2)
{
// Big chunk of code here
}
Rather than
Code:
if (Value == Value2)
Goto GotoStatementName;
And if there is a difference, by how much? Its just i don't really like the idea of having a massive If statement and to me the second option looks a lot cleaner and easier to follow, is there a Big difference - Or would it compile more or less the same? :tongue:
~ Jeax
Re: Goto statement - The problem?
1) Goto statements are *not* useful in any occasion. If you ever have need to use one it's a show of a failure in design on your own part. I've never ever used one, or felt the need to.
2) How you see it is way different from how your CPU sees it after compilation. Additional brackets, whitespace and such don't add any processing time at all. If you let the program flow after an IF statement, it will be less than having your program jump to another location and THEN completing the task. Besides, like I already mentioned GOTO statements are poor design, make your program difficult to follow (even for yourself) and all other rosy things along those lines.
On ASM level your examples evaluate to pretty much the same depending on the situation, but the reason you shouldn't use a goto statement is above.
Re: Goto statement - The problem?
Fun to use to write unreadable code :P
JOB SECURITY!
Re: Goto statement - The problem?
I don't see anything wrong with goto statements; they're handy sometimes in situations where you cbf.
Re: Goto statement - The problem?
I totally agree with Negata. Using goto shows that you fail at writing code. If you're a good programmer, you can avoid using goto statements easily, by using functions/loops.
As well as it shows you lack in programming, it either makes your code unreadable and messy. I have seen people here using it, it could easily be done otherwise and made the code look messy and hard to read.
I can't think of a situation where you have to use it...I have never even heard about the statement till a few months ago. Never felt the need to use it ^^
Re: Goto statement - The problem?
lol this sounds daft but the only goto statement i use is in flash :D
Re: Goto statement - The problem?
Never used GoTo. Never needed to. It's just one of those things which doesn't really seem necessary in programming.
Re: Goto statement - The problem?
i rarely use it on infinites loops that are on other infinite loops, but i can also use flag to avoid it. Sometims it are usefull, but i must accept that using it too many times makes the code hard to read
Re: Goto statement - The problem?
It can start very bad habits. As a programmer you want to make your code as legible and neat as possible. Once you start making programs with thousands of lines of code goto statements will be confusing and make it almost impossible to read. Lastly, never expect to be hired as a programmer if you are still using goto statements and...
Code:
if(value == value2)
return 0;
instead of
Code:
if(value == value2)
{
return 0;
}
P.S. A good book to read on how to program properly is C++ in Action
Re: Goto statement - The problem?
Whats wrong with a two line If statement :tongue:
Its easy to read (When indented obviously) But i've never found it harder to read.
Re: Goto statement - The problem?
Quote:
Originally Posted by
Jeax
Whats wrong with a two line If statement :tongue:
Its easy to read (When indented obviously) But i've never found it harder to read.
I use the brackets, makes it little bigger but gives less confusion, also it is easier to read.