[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y ] [Search | Free Show | Home]

Do you ever use goto, anon? Why or why not?

This is a blue board which means that it's for everybody (Safe For Work content only). If you see any adult content, please report it.

Thread replies: 57
Thread images: 5

File: goto-statement.png (17KB, 369x200px) Image search: [Google]
goto-statement.png
17KB, 369x200px
Do you ever use goto, anon?

Why or why not?
>>
Yes, because I occasionally write in assembly
>>
I'm not a kernel developer, so no.
>>
>>58909183
yeah
mostly for cleanup code
>>
>>58909183
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.
>>
File: IMG_5461.jpg (202KB, 2048x1024px) Image search: [Google]
IMG_5461.jpg
202KB, 2048x1024px
For loops in assembly.
>>
File: 1482526689518.jpg (263KB, 764x551px) Image search: [Google]
1482526689518.jpg
263KB, 764x551px
>tfw too intelligent to fall for the structured programming meme
>>
>>58909318
>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
>>
>>58909183
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
>>
>>58909183
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.
>>
>>58909791
How would you design assembly better?
>>
>>58909318
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..
>>
>>58909802
If you read my comment I said (except ASM) huuur duur!
>>
>>58909889
Okay then, how would you design this "ASM" language better?
>>
>>58909899
Are you retarded?
>>
>>58909899
Oh sorry.. you must be new... ASM is Assembler.. I've been doing this for a few decades, I just assume everyone knows that...
>>
>>58909589

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.
>>
>>58909183
Yes, I use it in C#.

Why people hate it? It is very useful
>>
>>58909943
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
>>
https://www.youtube.com/watch?v=m9joBLOZVEo
>>
>>58909943
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;
}
>>
>>58911696
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.
>>
>>58909323
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.
>>
>>58909183
No

I never had a reason to use it
>>
goto is cancer
>>
>>58911802
boolean done=false;
do {
try
{
do_something();
done=true;
}
catch(const some_specific_exception&)
{
fix_that_shit();
}
} while (!done);
>>
>>58909604
This guy knows what he is talking about!
>>
>>58909183
Nope, because in asm it's called jmp.
>>
>>58912497
what issue does this fix?
>>
>>58909183
In assembly. I never needed to in proper languages.
>>
>>58909467
>tfw can't get a job
>>
>>58909845
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
>>
File: gotolulz.png (8KB, 538x232px) Image search: [Google]
gotolulz.png
8KB, 538x232px
>>58909183
>>
>>58909318
>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.
>>
>>58909183
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
>>
>>58914139
Do any development environments point out fuck-ups like this? The obvious catch is that the third if could never be reached...
>>
>>58912993
readability.
>>
>>58914304
Interesting... Criticisms? Overengineered?
Mixing break and no break is pretty coder-error prone...
>>
>>58914455
It just werks if there are about 5 options.
>>
>>58912993
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.
>>
>>58914139
This is why you always put brackets around your if blocks
>>
>>58909183
i wrote some vbscript the other day and i used an "on error goto 0" command
no regrets
>>
>>58914777
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.
>>
>>58913696
How do you not know about break or continue?
>>
>>58915215
>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.
>>
>>58909988
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.
>>
File: debugging legacy FORTRAN.png (135KB, 377x393px) Image search: [Google]
debugging legacy FORTRAN.png
135KB, 377x393px
>>58914720
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.
>>
>>58915231
>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.
Thread posts: 57
Thread images: 5


[Boards: 3 / a / aco / adv / an / asp / b / bant / biz / c / can / cgl / ck / cm / co / cock / d / diy / e / fa / fap / fit / fitlit / g / gd / gif / h / hc / his / hm / hr / i / ic / int / jp / k / lgbt / lit / m / mlp / mlpol / mo / mtv / mu / n / news / o / out / outsoc / p / po / pol / qa / qst / r / r9k / s / s4s / sci / soc / sp / spa / t / tg / toy / trash / trv / tv / u / v / vg / vint / vip / vp / vr / w / wg / wsg / wsr / x / y] [Search | Top | Home]

I'm aware that Imgur.com will stop allowing adult images since 15th of May. I'm taking actions to backup as much data as possible.
Read more on this topic here - https://archived.moe/talk/thread/1694/


If you need a post removed click on it's [Report] button and follow the instruction.
DMCA Content Takedown via dmca.com
All images are hosted on imgur.com.
If you like this website please support us by donating with Bitcoins at 16mKtbZiwW52BLkibtCr8jUg2KVUMTxVQ5
All trademarks and copyrights on this page are owned by their respective parties.
Images uploaded are the responsibility of the Poster. Comments are owned by the Poster.
This is a 4chan archive - all of the content originated from that site.
This means that RandomArchive shows their content, archived.
If you need information for a Poster - contact them.