Why is goto a bad programming practice?

I have been thinking about ths for some time but can't find any plausible answer. What is the reason, exactly, that a goto statement is considered harmful? Why is it bad programming practice? I have been trained to write programs without goto and also avoid using it, but what is the thing actually hat makes it bad programming anyway? The only reason I have found it to be considered bad programming practice is due to a paper by Djikstra, but I haven't been able to get the paper.

4 Answers

Relevance
  • 9 years ago
    Favorite Answer

    Goto creates what is called "spaghetti code", where you can jump from one place to another without regard for consequences, back as well as forth. Structural languages can do without, using well-constructed loops and checks for certain conditions.

    In my personal experience (having seen literally thousands of lines of code made by dozens of different people), use of Goto is what differentiates the noobs from the more experienced programmers.

    Get stuck on what a value is supposed to be like? Use a Goto and try again. Need to skip over a pice of code if a certain condition isn't met? Use Goto. It pretty much indicates a lack of understanding how to do proper value-checking or how to use conditional statements and functions.

    Visual Basic (the starting language of choice for many beginners, therefor often looked down upon by many programmers, who balefully neglect the fact that it can be quite the powerful language) is the biggest culprit in the Goto culture (stemming from the days of Basic, GWBasic and QBasic).

    Overall, the use of Goto can be avoided by smarter programming, making for code that is easier to read and debug (especially in environments where multiple programmers work on a single project).

  • 9 years ago

    GOTO allows for what is called "spaghetti code", a tangle of commands whose structure are convoluted. Debugging in this case is a major pain because the programmer can have a very hard time visualizing the logic behind the code. Functionally, there is very little difference between GOTO and a method call, though some differences do exist.

  • Anonymous
    9 years ago

    This is considered bad practice because it produces what is known as "spaghetti code" which is hard to follow. Consider the power you have at your hands in an object oriented language and there is no power in using a goto statement. If you are using goto you need to rethink your algorithm.

    Source(s): Computer Guru at www.computingsolutionskc.com Old School C Programmer
  • 3 years ago

    you need to use a loop fact to no longer exhibit blunders. And there is blunders/warning even in C#, yet they are only no longer being displayed (this is a parameter to the compiler). attempt this quite: /* software to be certain if enter character is a vowel */ #comprise<stdio.h> void considerable() {  char ans;  bool performed = fake;  /* Loop till performed */  jointly as (performed == fake)  {    printf("enter a character in decrease case: ");    scanf("%c",&ans);    change(ans)    {    case 'a':      printf(" character is 'a' this is vowel");      performed = real;  /* set flag that it's time to go out the loop */      smash;    case 'e':      printf(" character is 'e' this is vowel");      performed = real;  /* set flag that it's time to go out the loop */      smash;    case 'i':      printf(" character is 'i' this is vowel");      performed = real;  /* set flag that it's time to go out the loop */      smash;    case 'o':      printf(" character is 'o' this is vowel");      performed = real;  /* set flag that it's time to go out the loop */      smash;    case 'u':      printf(" character is 'u' this is vowel");      performed = real;  /* set flag that it's time to go out the loop */      smash;    default:      printf(" entered character isn't a vowel");      smash;    }  } }

Still have questions? Get your answers by asking now.