Linux Shell 'cd' replacement tool. cd on steroids, with fuzzy file finder and a directory bookmark saver.

Being pressured to GOTO the dark-side

We have a situation at work where developers working on a legacy (core) system are being pressured into using GOTO statements when adding new features into existing code that is already infected with spaghetti code.

Now, I understand there may be arguments for using 'just one little GOTO' instead of spending the time on refactoring to a more maintainable solution. The issue is, this isolated 'just one little GOTO' isn't so isolated. At least once every week or so there is a new 'one little GOTO' to add. This codebase is already a horror to work with due to code dating back to or before 1984 being riddled with GOTOs that would make many Pastafarians believe it was inspired by the Flying Spaghetti Monster itself.

Unfortunately the language this is written in doesn't have any ready made refactoring tools, so it makes it harder to push the 'Refactor to increase productivity later' because short-term wins are the only wins paid attention to here...

Has anyone else experienced this issue whereby everybody agrees that we cannot be adding new GOTOs to jump 2000 lines to a random section, but continually have Anaylsts insist on doing it just this one time and having management approve it?


How can one go about addressing the issue of developers being pressured (forced) to continually add GOTO statements (by add, I mean add to jump to random sections many lines away) because it 'gets that feature in quicker'?

I'm beginning to fear we may lose valuable developers to the raptors over this...

Credit: XKCD


Goto here

alsoThere: No, I'm talking about the kind of goto that jumps 1000 lines out of one subroutine into another one mid way into a while loop. Goto somewhereClose

there: I wasn't even talking about the kind of gotos you can reasonably read over and determine what a program was doing. Goto alsoThere

somewhereClose: This is the sort of code that makes meatballs midpoint: If first time here Goto nextpoint detail:(each one almost completely different) Goto pointlessReturn

here: In this question, I was not talking about the occasionally okay use of a goto. Goto there

tacoBell: and it has just gone back to the drawing board. Goto Jail

elsewhere: When it takes Analysts weeks to decypher what a program is doing each time it is touched, something is deeply wrong with your codebase. In fact, I'm actually up to my hell:if not up-to-date goto 4 rendition of the spec goto detail pointlessReturn: goto tacoBell

Jail: Actually, just a small update with a small victory. I spent 4 hours refactoring a portion of this particular program a single label at a time, saving each iteration in svn as I went. Each step (about 20 of them) was smallish, logical and easy enough to goto bypass nextpoint: spontaneously jump out of your meal and onto you screen through some weird sort of spaghetti-meatball magnetism. Goto elseWhere bypass: reasonably verify that it should not introduce any logic changes. Using this new more readable version, I've sat down with the analyst and completed almost all of this change now. Goto end

4: first *if first time here goto hell, no second if first time here goto hell, no third if first time here goto hell fourth now up-to-date goto hell


Source: (StackOverflow)

Is there a label/goto in Python?

Is there a goto or any equivalent in Python to be able to jump to a specific line of code?

Source: (StackOverflow)


How can I use goto in Javascript?

I have some code that I absolutely must implement using goto. For example, I want to write a program like this:

repeat: goto start

Is there a way to do that in Javascript?

Source: (StackOverflow)

Does anyone still use [goto] in C# and if so why? [closed]

I was wondering whether anyone still uses the "goto" keyword syntax in C# and what possible reasons there are for doing so.

I tend to view any statements that cause the reader to jump around the code as bad practice but wondered whether there were any credible scenarios for using such a syntax?

Goto Keyword Definition

Source: (StackOverflow)

Is it ever advantageous to use 'goto' in a language that supports loops and functions? If so, why?

I've long been under the impression that 'goto' should never be used if possible. While perusing libavcodec (which is written in C) the other day, I noticed multiple uses of it. Is it ever advantageous to use 'goto' in a language that supports loops and functions? If so, why?

Source: (StackOverflow)

How to break out of multiple loops at once in C#?

What if I have nested loops, and I want to break out of all of them at once?

while (true) {
    // ...
    while (shouldCont) {
        // ...
        while (shouldGo) {
            // ...
            if (timeToStop) {
                break; // Break out of everything?

In PHP, break takes an argument for the number of loops to break out of. Can something like this be done in C#?

What about something hideous, like goto?

// In the innermost loop
goto BREAK
// ...
BREAK: break; break; break;

Source: (StackOverflow)

Alternative to a goto statement in Java

What is an alternative function for the goto keyword in Java?

Since Java does not have a goto.

Source: (StackOverflow)

How do I get GDB to break out of a loop?

I can tell GDB to return from a function immediately with return, and call a function with call myFunction.

But how do I get it break out of the current loop? i.e. to act as if it's hit a break; statement.

Is jump myfile.c:<linenumber> the way to do this?

Source: (StackOverflow)

Is there a goto statement in Java?

I'm confused about this. Most of us have been told that there isn't any goto statement in Java.

But I found that it is one of the keywords in Java. Where can it be used? If it can not be used, then why was it included in Java as a keyword?

Source: (StackOverflow)

Is GOTO in PHP evil? [closed]

I recently found out that PHP 5.3 supports new language construct called GOTO. Everybody knows what it does. However, it's not exactly the traditional GOTO, it's just a jump label. I'm interesting in knowing whether this GOTO is evil and implies bad code?

Source: (StackOverflow)

Will using goto leak variables?

Is it true that goto jumps across bits of code without calling destructors and things?


void f() {
   int x = 0;
   goto lol;

int main() {
   return 0;

Won't x be leaked?

Source: (StackOverflow)

Is there a "goto" statement in bash?

Is there a "goto" statement in bash ? I know It is considered bad practice, but I need specifically "goto".

Source: (StackOverflow)

Why does Go have a "goto" statement

Google's Go language is a new language. Therefor I was surprised to find that it has a 'goto' statement. I've always been taught that 'goto' statements are a thing of the past and evil for it occludes the actual flow of a program. Function (or methods if you will) are always a better way of controlling flow.

I must be missing something. Why and when is using 'goto' a good idea? Or why did Google include it?

Source: (StackOverflow)

Goto out of a block: do destructors get called?

Consider the following code:

void foo()
        CSomeClass bar;

        // Some code here...

        goto label;

        // and here...

    // and here...

Will the destructor of bar be called ?

Source: (StackOverflow)

Valid use of goto for error management in C?

This question is actually a result of an interesting discussion at programming.reddit.com a while ago. It basically boils down to the following code:

int foo(int bar)
    int return_value = 0;
        if (!do_something( bar )) {
                goto error_1;
        if (!init_stuff( bar )) {
                goto error_2;
        if (!prepare_stuff( bar )) {
                goto error_3;
        return_value = do_the_thing( bar );
        return return_value;

The usage of goto here appears to be the best way to go, resulting in the cleanest and most efficient code of all possibilities, or at least so it seems to me. Quoting Steve McConnell in Code Complete:

The goto is useful in a routine that allocates resources, performs operations on those resources, and then deallocates the resources. With a goto, you can clean up in one section of the code. The goto reduces the likelihood of your forgetting to deallocate the resources in each place you detect an error.

Another support for this approach comes from the Linux Device Drivers book, in this section.

What do you think? Is this case a valid use for goto in C? Would you prefer other methods, which produce more convoluted and/or less efficient code, but avoid goto?

Source: (StackOverflow)