home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / arch / 10553 < prev    next >
Encoding:
Text File  |  1992-11-09  |  3.5 KB  |  66 lines

  1. Newsgroups: comp.arch
  2. Path: sparky!uunet!ukma!darwin.sura.net!convex!news.oc.com!utacfd.uta.edu!seas.smu.edu!shyamal
  3. From: shyamal@seas.smu.edu (Shyamal Prasad)
  4. Subject: What's wrong with goto's
  5. Message-ID: <1992Nov9.173229.15120@seas.smu.edu>
  6. Sender: news@seas.smu.edu (USENET News System)
  7. Nntp-Posting-Host: turbo_f.seas.smu.edu
  8. Organization: SMU School Of Engineering and Applied Science
  9. References: <Bx7GLJ.8DC@world.std.com> <CGAY.92Nov5221353@ilix.cs.uoregon.edu> <1992Nov7.231035.19157@pentagon-gw.army.mil>
  10. Date: Mon, 9 Nov 1992 17:32:29 GMT
  11. Lines: 53
  12.  
  13.     The 'goto' thread on the newsgroup is really something else. However
  14. it seems that the basic question is "What is wrong with the goto?",
  15. and no one seems to answer this one. This discussion may even be in
  16. the wrong group - but since there is so much interest, here goes.....
  17.  
  18.     Disclaimer: I am not here with all the answers,
  19. and nothing I have to say is very original, and I am not an
  20. authority on this. I am just trying to state a viewpoint that I
  21. feel has not been put strongly enough in this discussion.
  22.  
  23.     In the first place there is nothing wrong with the goto
  24. statement itself, it's the *label* that creates the problem ! (And
  25. this is a relatively well known, but often forgotten, viewpoint)
  26.  
  27.     "Understanding" a program is, in my opinion, about
  28. intuitively getting the hang of invariants. But when we see a goto
  29. our intuitive understanding of an invariant condition gets thrown off
  30. because we are really not sure where we "came from". We don't know
  31. (formally or intuitively) what the invariants are any more when we see
  32. a label. If we use labels and ensure that we jump to them 
  33. carefully enough that some (useful) invariant is always satisfied 
  34. then we are doing okay, are we not? After all if we are sure that a
  35. certain condition holds at a label we have *not* lost any clarity over
  36. an equivalent structured program without the goto.
  37.  
  38.     The reaction to the goto is a cultural thing. It just looks ugly,
  39. but we never *really* question why. Try implementing a finite machine
  40. with each state implemented with  code marked by a label. Transitions 
  41. between states are goto statements. I always do this - it works because
  42. each label marks an entry to a state of the machine, and the machine
  43. states are so well defined! I don't lose any clarity because my labels
  44. always have well defined invariant conditions on entry. This seems to be
  45. so much clearer than the so called 'structured versions' that I tried.
  46.  
  47.     Structured programming has little to do with the lack of using
  48. goto statements - it has to do with improving code clarity. I never read
  49. Herman Rubin's code, only because it was *so* unclear, if you use
  50. goto statements make sure they improve clarity. That is the final
  51. arbiter; I have always believed that efficient programs can be
  52. clear (with or without gotos). I am not sure if Rubin's code runs better
  53. with all those goto's or not, but the real point is that if he uses goto
  54. statements he should do it with discipline.
  55.  
  56.     I even ask myself : What is the use of break statements that
  57. are more powerful than the simple single level one like we have in C?
  58. CLU and ADA need some way to specify the level to which execution
  59. should exit. What is the point of replacing the goto ?? If we used
  60. a goto with a label *have we lost any clarity*? After all the label
  61. is there only to provide an early break or continue....use it in
  62. just that way ("keep you invariants true"). 
  63. -- 
  64. Shyamal Prasad, Department of Computer Science
  65. Southern Methodist University, Dallas TX 72275
  66.