Nested functions pros and cons

I suspect that most of this comes from Dijkstra’s “Go To Considered Harmful” essay, which people read and parrot without understanding the context. At the time this paper was written, structured control flow was a brand new concept and goto was how all control flow was done in practice. Dijkstra was trying to convince people to use structured control flow at all not convince them that they shouldn’t ever use goto.

The occasional, judicious use of goto is just fine, but (as always) consider the alternatives. If I can use a couple of gotos and have much clearer simpler code, that’s way better than writing the same thing with no gotos but a nasty, unintelligible mess of structured control flow—and there are some cases where this is the choice. The whole argument against goto was that unbridled use of it lead to complex unintelligible code, but readability and maintainability is the end goal by whatever means.

13 Likes