Gotos Considered Maybe Not Harmful

Way back in 1968, Edgar Dijkstra published a famous letter to the Communications of the ACM that explained why he felt the go to statement was being abused. Ever since then, lots of uninformed folks who haven’t bothered reading it and have missed the nuances in Dijkstara’s argument have been invoking it in what amounts to a jihad against using gotos in any circumstance. The letter almost wasn’t published because the editors felt it wasn’t that interesting and the famous title, “Go To Statement Considered Harmful” was actually written by one of the editors not Dijkstra.

The truth is, there are lots of circumstances in which gotos make perfect sense. I’ve used them myself but I always felt the need to document why my use didn’t violate some sacred dictum by referring to this paper by Knuth in the source code. It saved me a lot of pushback and I could tell those who persisted in arguing the point to direct their comments to Knuth.

Now Joe Marshall offers another example of acceptable goto use. It’s not clear from his post whether he’s using an explicit goto or merely pointing out that gotos occur implicitly in all programming languages. Certainly, the example of tail recursion is like that. His point is that tail recursion is simply a goto even if there’s no explicit goto involved.

The use of gotos that Dijkstra was arguing against is clearly a bad thing but that doesn’t mean that their use in specialized situations is a sign of sin.

This entry was posted in General, Programming. Bookmark the permalink.