Thread: Recursion?
View Single Post
  #23   Spotlight this post!  
Unread 15-12-2003, 10:43
mtrawls's Avatar
mtrawls mtrawls is offline
I am JVN! (John von Neumann)
#0122 (NASA Knights)
Team Role: Programmer
 
Join Date: Mar 2003
Location: Hampton, VA
Posts: 295
mtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to beholdmtrawls is a splendid one to behold
Send a message via AIM to mtrawls
Re: Recursion?

Quote:
Originally Posted by KenWittlief
GOTO statements are bad because a function or subroutine should have one entry point and one exit point - GOTO is used when you dont really know what you are doing- when you havent really worked out the inputs, output and processing that has to happen to get the outputs from the inputs - its an indication that the programmer started writing code BEFORE he figured out what the code had to do (failed to do the high level design work first)

its not something to avoid, its something you should never use - if you cant figure out how to parse your input, or navigate your data structures without using these shortcuts, then you need to go back and work on your data structures and algorythms somemore.
(emphasis mine)

Well, sure, generally speaking goto should be avoided. But like in all things, extremities should be avoided, and one must be careful not to avoid doing something merely for the sake of avoiding it. There are some insightful discussions on the internet I will refer everyone to, that can clear up the issue somewhat. Knuth has an interesting paper on the subject, titled Structured Programming with 'go to' Statements:

Quote:
Before beginning a more technical discussion, I should confess that the title of this article was chosen primarily to generate attention. There are doubtless some readers who are convinced that abolition of go to statements is merely a fad. and they may see this title and think, "Aha! Knuth is rehabilitating the go to statement, and we can go back to our old ways of programming again." Another class of readers will see the heretical title and think, "When are diehards like Knuth going to get with it?" I hope that both classes of people will read on and discover that what I am really doing is striving for a reasonably well balanced viewpoint about the proper role of go to statements. I argue for the elimination of go to's in certain cases, and for their introduction in others.
(please, read on; the quality is somewhat sketchy, though, and bear in mind it was written in the 70s)

And if Knuth isn't a big enough name, Edsger W. Dijkstra has written a paper called Go To Statement Considered Harmful. (And, for those famiar with perl, there is a nice discussion at perlmonks.com).

Just remember that there are different goals in writing programs. Some programs you want to be really fast, while others you want to have a low memory profile, while others still, you want to be very readable. A goto statement might not fit into the "readability" column (and everyone remember that premature optimization is -- indeed -- the root of all evil), but it might make something go faster, which in some cases is a higher objective. You ask whether to use the goto statement? To give the "MIT answer" as my old teacher used to say all too frequently: It depends. I think it is only folly to take away a potentially useful tool from a programmers tool box (sure, the programmer has to pay extra attention to make sure he uses the right tool for the right job ... but that applies everywhere).