2 ms·
This is probably going to be an unpopular opinion, I dont agree with the criticism of the use of goto. I know, I know, the classic "goto Considered Harmful". A
by hermitdev 7y ago
This is probably going to be an unpopular opinion, I dont agree with the criticism of the use of goto.
I know, I know, the classic "goto Considered Harmful". And, yes, it can be abused just like every other programming construct.
I see 2 generally good use cases for goto: 1) error handling to cleanup in failure in C (in C++ RIAA constructs ahould be used instead) 2) exitting nested loops, instead of a flag and a break.
I've also seen C++ code use do while loops with while(false) so that they could use "break" to exit the non loop. Its very confusing and non obvious, because you see the do, and thus expect a loop. Meanwhile (the absurdly long function) has the while(false) on a separate screen, not making it clear that the code doesn't actually loop. Just use the goto. It's clearer and omits the abuse of a looping primitive (that doesn't actually loop).
Yes, goto can be abused, so can many other statements.
Sorry, /rant