Re: Best and Neatest way to check status in C
Sorry this might me lame.. why does one statement better than the other like "goto & while"?? and why is "goto" considered evil; if thats the case why did they ever include it in the Language in the first place??. Sorry i'm new to programming just started 3days ago.
Thanks
Re: Best and Neatest way to check status in C
Quote:
Originally Posted by ch0co
why is "goto" considered evil;
In a nutshell, it encourages poor code structure, and most of its uses have been replaced by better programming constructs such as loops, functions, and exceptions.
One of the best indicators of good code structure is if you can read a function from top to bottom and it makes sense. Reading code that abuses goto, on the other hand, requires one to look up, down, left, right, and under their couch cushions to figure out the flow of execution.
Quote:
Originally Posted by ch0co
if thats the case why did they ever include it in the Language in the first place??
Goto was included in C++ mostly for backwards compatibility with legacy C code. I guess it was included in C because that language was drafted in the early days of structured programming, when using goto to control program flow was still a firmly embedded habit among programmers. To this day there is a small contingent of programmers who feel that goto is useful enough to warrant being a feature of both C and C++, and one of the reasons for this is presented in this thread.
Quote:
Originally Posted by ch0co
Sorry i'm new to programming just started 3days ago.
No apology necessary :). Best of luck.
Re: Best and Neatest way to check status in C
Please go re-read posts 1, 6, 9, 11, and 12.
All computer programs are sequences of instructions and gotos (or branch instructions).
The purpose of a high-level language is to make it easier to organize and maintain the structure of a computer program, by allowing use to use more abstract constructs.
The more abstract the construct (not vague, which is different) the easier it is to manage.
It is the difference between asking someone to make a peanut butter and jelly sandwich and instructing them how to move each muscle in their body to do the same.
However, sometimes you still want to manipulate a specific muscle.
[edit] man... too slow again...
[edit2] i've also got to learn to spell
Re: Best and Neatest way to check status in C
In addition:
At machine/assembly level 'goto' would just break the flow in totally un-conditional manner. Stack variables may not be destroyed, destructor would not be called. Stack may also be corrupted. With exceptions, goto may cripple the whole program flow. The CPU cannot maintain code-coherency (say, code "caching") - thus program would run slow than expected.
There may be be some uninitialized variables, as goto might have skipped the code where variable is initialized.
Debugging with 'gotos' is real pain - you cannot determine the flow while doing code review. It would be hard to maintain code (since flow is jagged!).
Re: Best and Neatest way to check status in C
thnx.. I think I get it now