C++, why are people so afraid of GOTO?

Been working on a C++ project.

Use GOTO a lot to make things work.

Other people call me an idiot and change my code on the repo without telling me.

Why is GOTO so hated?

Attached: 1_YU6BvZKvxivoEnvqxeG5rw.png (918x1032, 47K)

Other urls found in this thread:

koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/
en.wikipedia.org/wiki/Loop_unrolling
ark.intel.com/products/52229/Intel-Core-i5-2520M-Processor-3M-Cache-up-to-3_20-GHz
tutorialspoint.com/cplusplus/cpp_functions.htm
twitter.com/AnonBabble

It gives me vietnam-style assembler flashbacks

blame dijkstra

grug digging a C grug grug stone cave
Use GOTO a lot to make things work grug happy
Other tribe call grug idiot and writes over his hieroglyphics in the stone wall
Why do modern tribe hate GOTO

Attached: index.png (235x215, 9K)

supposedly makes source difficult to read and usually you can substitute goto for a loop

GOTO has its place (ex. conditional guards and exiting from nested loops)
overusing it is stupid. blindly hating on it is also stupid.

Because if you ever feel the need to use goto in C++, you should have written it in C instead. It's a very strong indicator of either your architecture being shit or you choosing the wrong tool. Even in C, the usage of goto is restricted to very few cases.

Post how you're using it.

It makes reading your code more bothersome, desu, and can just be avoided.

literally who?

It's like using a flamethrower for pest control
There are better ways to do it that makes your code more readable, like loop and functions
Especially in C++

>C++
>functions
lol

just use while/do while.

Goto can prevent your systems from being parallel.
Makes it more difficult to do static and dynamic analysis.

Literally anything can if used retardedly.

Tell them they're Retard full big.

The underlying assembly is basically one big goto.

Goto is hated because it is harder for the compiler to tell what is going on and it is never needed.
The typical use for goto in a modern setting is when handling errors.
So basically, the flow is an upstart of sorts and then you have a common error handling part.
Every error you detect just branches to the error part of your code and then you can gracefully stop or recover or whatever.
The thing is: YOU DON'T NEED THIS.
Calling a function is just as easy and much easier to read.
Having a destructor is even better as you know it will be automatically called when the class is out of scope.
And the programming community have concluded that the only reason to use goto is so kids can learn about branching without switching to asm.

- code harder to automatically optimize
- harder to read ( control jumps everywhere )

I suggest you cut your code to smaller inlined functions and use returns( instead of gotos) it is much more readable and is actually a good practice..

It interferes with compiler optimizations

Yes, functions, or what they call methods in Java, etc

You know, where you start your program with public main(){
//whatever you're working on
}

"GOTO is considered harmful"
Most people are dumb like the reddit & Jow Forums userbase and they think that mean "GOTO is harmful". They're extremely stupid. This is why we have a lot of stupid political movement those days... people... they just can't understand the meaning of anything nowadays. Dumb 4chanredditors.

What?
For loop is literally a GOTO, While loop actually forget it, every single loop is a GOTO.

Do develop what you're saying further, user
I haven't done C++ yet, I'd like to know (who knows, it'll help)

Google Dijkstra 's algorithm

>what is loopunrolling
put your head out of your ass and actually take some useful advice you noob

Goto doesn't compile the same was a for loop would. Gotos have to check conditions at runtime, not at compile time.

loop unrolling is retarded idea by retards who think that any instance of GOTO is bad. Like yourself.

kys

koblents.com/Ches/Links/Month-Mar-2013/20-Using-Goto-in-Linux-Kernel-Code/

Give an instance where it would be more advantageous to use goto

Compile sees loop as goto commands, no matter how much gotos you put in, it will compile the same as for loop.

en.wikipedia.org/wiki/Loop_unrolling

>goto doesn't compile the same way a for loop would
It's literally the same - cmp followed by a conditional jump to some label.

Irrelevant, you are trying to fix an issue that doesn't exist.
What is benefit of unrolling a loop other than writing more code?

oh, only one of the most famous computer scientists in history. Guess they don't teach him at coding bootcamps

The whole loop discussion is irrelevant because no one is using gotos for loops. In real life situations they're useful if there's some error handling or clean up before exiting a function. Gotos can be more readable than nested ifs.

Come on man, I can't program for shit and even I know that is.

Attached: I_am_the_liquor.gif (268x234, 1022K)

>Does C++ (and thus C) have tags like assembly does?

>GOTO
CONSIDERED

>Reddit spacing

Anyways, it's bad design to use goto unnecessarily. There are times where you just gotta hit the ejector seat button and get the hell out of there.

goto is good for breaking out of nested loops

Unrolling is compile-time optimisation, it pulls more code into the CPU cache at a time. Thus, less cache misses in execution, and lower general latency in execution.

>Use GOTO a lot
Nothing wrong with the odd GOTO
>to make things work.
This is where you fucked up.

Gimme some situations where you're using goto.

Now only if you could find [citation] for your claim, because all the papers I read about this shit, concluded that over 6 loops and unrolling is not effective and pretty much can be disregarded.

I see at least 2 problems with it
>it seems like it's not your repo, which means that you should try to keep using the same style and conventions when contributing to it
>goto is not necessarily bad but at the same time there are a lot of other ways to do things than using it and since its use outside of asm is abysmal compilers not always are programmed to optimize it well.

optimization does not exist ?
hahahaha you are completely unfit to be a programmer

yes you will get a lot of misses with 3MB of l2 cache for a shit tier intel CPU

ark.intel.com/products/52229/Intel-Core-i5-2520M-Processor-3M-Cache-up-to-3_20-GHz


Haahahahaha your parents must be proud of your extraordinary intelligence..!

Someone once said goto were harmful and now no one try to understand the context and just blindly never use goto.
In the end it's just another tool in your toolbox, just use it where it make sense.

it happens automatically you moron if you dont use gotos to loop like a retard thats what we are saying all this thread

>It makes reading your code more bothersome
Couldn't make it any more bothersome than someone who uses lots of classes.

what?

I can understand GOTO in C (jump to error-handling/cleaning tail), but why in C++ when you want to use try-catch blocks instead of that?
post examples where you like to use it

Depends on how classes are used.

Using GOTO is a bad habit to get into especially when learning.

I don't think you understand.
Every single loop has GOTO as compiled assembler code.

Ohhh man i wish Terry see that shit :D

/thread

Actually most good compilers unroll goto loops just fine as long as you're not doing some completely retarded shit. Anyway there's no reason to loop with goto.

I mean yes you can use it but if u show it to somebody he will be very suprised.

>exiting from nested loops
Don't say you actually do this.
Why not just use a return?

When I want to change the order of some code execution with minimum alterations on my commit.

Because we has a society agreed that loops make more sense.

Well the other people are right you really are a brainlet idiot.

Whoever makes less changes creates less errors.

I think I've found something that can help you out tutorialspoint.com/cplusplus/cpp_functions.htm

>whatis break;

Not him but
fun(){
loop1{
loop2{
//You are here
}
}
}

Exiting to fun() takes two break statements and just one goto. A return statement stops the function altogether

Do
{
Do
{ stop=1;
break;
//a sane person would just do a return
} while(!stop)
} while(!stop)

A sane person would use code tags