I know it's considered to be harmful, but we have already a convention in our company to use gotos to jump to the end of a function for cleanup purposes. While talking about that with him, I said I could also think of other situations where gotos can be helpful and he asked which and I said I oftentimes like to use them to jump over code, so instead of writing something like:
Code: Select all
int func()
{
step1;
step2;
step3;
if (x) {
step4;
step5;
step6;
step7;
}
step8;
step9;
step10;
return 0;
}
Code: Select all
int func()
{
step1;
step2;
step3;
if (!x) {
goto over_steps4567;
}
step4;
step5;
step6;
step7;
over_steps4567:
step8;
step9;
step10;
return 0;
}
He told me he didn't agree at all and asked me whether I thought I was smarter than all these programmers out there who say goto is bad and said I wasn't allowed to write such kind of code any more. I usually don't bother too much when he criticises that I place too many or too few blank lines between my functions or whatever detail of my coding style he doesn't like, but this really brought me upset. What do you guys think; is this already "bad use" of goto?