The few times I've seen gotos in working code, I reacted much the same way. On those occasions I can recall offhand, one was a higly optimized bit that, frankly, should have been redone in assembly anyway; aother was simply a bad piece of code that I ended up rewriting (I'm not exactly the best coder in the world myself, but I could see the flaw in what the other person had done pretty clearly).
The remainder were all cases of using it to escape from a deeply nested loop in a language (C, Pascal or Modula 2) that didn't support labelled breaks. While sometimes these could be redone, there were a few in which there was no obvious way of rewriting the loops to avoid it that wouldn't result in even worse maintanence problems. Sometimes, even the best principles need to be set aside for practical reasons.
The Modula-2 one surprised me, as there was an obvious, if somewhat clumsy, way to avoid it. It was in a tutorial (on recursive-descent compiler design), and didn't contribute to the speed to any significant degree, so it was particularly unjustifiable IMAO. |