This is the best rant on the demise of the goto statement I have ever heard. It is from the Tango conference 2008 – Fibers talk by Mikola Lysenko. If you fast forward to 23 min 05 secs, you will hear this:
One way you can think about states [in a state machine] is that they’re kind of a label. And you put this label here for where you want the code to goto after you’re done with this other, sort of, state. A state machine is kind of an indirect goto and so these states and switch statements are just like nested gotos within gotos.
Now if you use coroutines, you can then use structured programming to represent the states. I mean this is a debate that was you know, played out years ago in a more limited context of structured programming versus gotos and ultimately, structured programming won out.
Nowadays I mean if you go into entry level programming course, they’ll just fail you on your projects if you even use a goto statement because those goto statements are that toxic to the integrity of programming code. You’re much better off using structured programming. And yet despite that, people still advocate using these state machines which are basically a really indirect horrible obfuscated goto mess, just split across multiple source files and larger projects.
So it’s like if you make the goto sin big enough, then no one is going to call you on how bad it is! But the thing is if you use coroutines, not a problem! So why have we been using this all along? Oh once again I’d probably appeal to the fact that, ah, you know, ignorance, right, people just don’t know about coroutines.
Now I want my goto back… er… coroutines!
1 response so far ↓
David Robinson // October 31, 2008 at 5:35 am |
I’m partial to Linus Torvalds’ rant on the demise of goto. Always makes me smile
”
> However, I have always been taught,
> and have always believed that “goto”s
> are inherently evil. They are the creators
> of spaghetti code
No, you’ve been brainwashed by CS people who thought that Niklaus Wirth actually knew what he was talking about. He didn’t. He doesn’t have a frigging clue.
”
Well said that man. See http://kerneltrap.org/node/553/2131 for more.
Cheers
David