Do you ever use goto, user?

Do you ever use goto, user?

Why or why not?

Other urls found in this thread:

youtube.com/watch?v=m9joBLOZVEo
twitter.com/SFWRedditVideos

Yes, because I occasionally write in assembly

I'm not a kernel developer, so no.

yeah
mostly for cleanup code

The only real valid use case in a modern language is for breaking out of nested loops. That's the only case where it is actually easier to read and understand with a goto than by keeping track of variables to tell you whether to break out of a loop.

For loops in assembly.

>tfw too intelligent to fall for the structured programming meme

>The only real valid use case in a modern language is for breaking out of nested loops.

Java has labeled breaks, which is sufficient, I think.

Yes for fucking error handling

goto is good for writing state machines. Other than that, I haven't had a use for it. Maybe I've used it a time or two with the following form, but it never reaches production.

some_stuff();
if (fail) goto err;
some_other_stuff();
err:
cleanup();
return;

I prefer comefrom.

I prefer pseudo-branching

Never use a goto, no need for it except for quick and dirty testing.

If you find yourself having to use goto, either your language is poorly designed (except ASM) or you haven't thought through the problem enough.

How would you design assembly better?

A modern language will have a "break" or "exit" statement for breaking out of nested loops, goto only makes your code look like spaghetti and you'll blow up the stack if you do that enough. Stack overflows are hard to debug..

If you read my comment I said (except ASM) huuur duur!

Okay then, how would you design this "ASM" language better?

Are you retarded?

Oh sorry.. you must be new... ASM is Assembler.. I've been doing this for a few decades, I just assume everyone knows that...

break, continue, try catch finally, so many ways... if you use goto outside asm you should be put to death

In assembly, yes but I rarely have to write that.
I use the same structure when I write JavaScript, but that is mostly because I am bad at JavaScript.
I write most of my programs in C++ and I never use goto there.
I also stay away from switch cases as much as I can, but they are much more clear and I can trust other people to immediately know what is going on there.

Yes, I use it in C#.

Why people hate it? It is very useful

This!... Overuse, or using a goto at all is just poor style and bad practice.

The road to failure is paved with goto's
~Zen of programming

youtube.com/watch?v=m9joBLOZVEo

Goto's are ok for error handling in C, as other anons already mentioned. It actually makes the code easier to read if you use them properly. Take a look at Linux sources.

I normally write the quickest way to get functional software then go back and replace goto stuff with if then statements and while do loops

retry:
try
{
do_something();
}
catch(const some_specific_exception&)
{
fix_that_shit();
goto retry;
}

boolean done=false;
while (!done)
{
try
{
do_something();
done=true;
}
catch(const some_specific_exception&)
{
fix_that_shit();
}
}

I used to use it as my first language was BASIC (ZX81), but I don’t anymore because I haven’t found so far any legitimate reason to use it instead of the other built-in features C offers, and it makes —in my opinion— the code uselessly too hard to debug.

how much would a chair like that cost? I want to be comfy af and look like a literal boss while I sit around and shitpost here.

No

I never had a reason to use it

goto is cancer

boolean done=false;
do {
try
{
do_something();
done=true;
}
catch(const some_specific_exception&)
{
fix_that_shit();
}
} while (!done);

This guy knows what he is talking about!

Nope, because in asm it's called jmp.

what issue does this fix?

In assembly. I never needed to in proper languages.

>tfw can't get a job

You are retarded and missed the point entirely. Using break when you are in nested loops requires you to set a variable, break, check the variable, break, check the variable, break, etc... The more nesting the more variable checking you have to do.

Are you seriously mentally challenged? Why would you want all that extra code when you could literally just have a single goto?
>but muh principles
>teacher said so

"If you want to go somewhere, goto is the fastest way to do that"
Ken

...

>The only real valid use case in a modern language is for breaking out of nested loops
common exit handlers and common cases in switch statements are also valid.

You could always extract them to a separate function, but that just adds clutter to the code.

For stuff like this
loop bla:
switch (somevar):
case(x):
bla()
goto somestuff
case(y):
blub()
goto somestuff
case(z):
onlyDoZ()

label somestuff:
doStuff()

end
end

so I don't have to rely on fallthrough alone

Do any development environments point out fuck-ups like this? The obvious catch is that the third if could never be reached...

readability.

Interesting... Criticisms? Overengineered?
Mixing break and no break is pretty coder-error prone...

It just werks if there are about 5 options.

it's unnecessary to check the value of "done" before the first loop. it will always be "false". So use a post-checked loop.

ITT: people not realizing that the goto that modern languages use is literally nothing like the goto Dijkstra criticized.
People used to jump in the middle of loops (where you could also set the index variable to be literally in the middle of the loop) or somewhere within functions with goto.

This is why you always put brackets around your if blocks

i wrote some vbscript the other day and i used an "on error goto 0" command
no regrets

More importantly, this is why you need a pre-commit hook to detect when there's no brackets, or add them before committing. You can't just count on humans always putting the brackets.

How do you not know about break or continue?

>when you are in nested loops
A lot of programming languages don't allow you to break out of nested loops. Some of those languages have gotos.

I use C# as well however I can't really see any benefit of using a goto when there are so many other ways to accomplish similar tasks.

I don't know about your "modern" languages, but goto is just as much of a bother in modern fortran95 as it was in old-fashioned f77.

>A lot of programming languages don't allow you to
Good thing it's still 1977 and silly things like "enddo" are still largely compiler-dialects or otherwise one might argue that language design has progressed beyond that point.