BASIC has a rather controversial statement in the family of jump statements called GOTO. The GOTO statement lets you move the flow of control to any point in the source code that you desire. It was usually used within the THEN or ELSE clause of an IF statement. But, if you had numerous nested-IFs it could be difficult—if not impossible—to look at the source code and have any idea what it was going to do. So, you had to be careful how you wrote your code. You still do.
At the time, there was some debate on the use of this statement with respect to the maintainability of source code. And, it was much frowned upon in many circles to the point where one would be judged badly for using it.
Well, this morning, as I sifted through the changes in the C# Language Specification 5.0, I came across the goto statement. I smiled and thought to myself, “They haven’t killed you yet?” I kind of like the GOTO statement. It lets you do what you want to do; however you like . . . make up your own rules . . . you can be a rebel if you like (kind of like commas, semi-colons, em-dashes and ellipses in grammar),
Then I remembered this essay, “A Case against the GO TO Statement,” by Edsger W. Dijkstra, the creator of the algorithm for finding the shortest path from a to b in a directed graph; or in layman’s terms, the initial ancestor of the algorithm that Google maps or your GPS receiver uses when it plots how to get from your house to the grocery store within the shortest amount of time or distance—kind of a hard thing to do.
Having studied and used some of his algorithms in college, he certainly had and still has my respect. And, if you’ve ever used a GPS, he should have yours as well. He kind of knows what he’s doing wouldn’t you say?
Back in school when I came up on the essay, I gave it strong consideration when he said:
The go to statement as it stands is just too primitive, it is too much an invitation to make a mess of one’s program.
With the exception of using, say, JMPs in assembly language (the equivalent of a GOTO in BASIC), I have tried to avoid using them as much as I can for the very same reason he states above.
But, I am happy that you can still GOTO in C#. So, if you feel like being a bit of a rebel . . . GOTO for it! Just don’t over do it . . . the Map Man might come looking for you (and he knows the quickest way to get to your house!)