home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / misc / 3486 next >
Encoding:
Text File  |  1992-11-04  |  3.7 KB  |  79 lines

  1. Newsgroups: comp.lang.misc
  2. Path: sparky!uunet!charon.amdahl.com!pacbell.com!decwrl!spool.mu.edu!agate!linus!linus.mitre.org!boole.mitre.org!crawford
  3. From: crawford@boole.mitre.org (Randy Crawford)
  4. Subject: Re: Pointers
  5. Message-ID: <1992Nov5.051745.7369@linus.mitre.org>
  6. Sender: news@linus.mitre.org (News Service)
  7. Nntp-Posting-Host: boole.mitre.org
  8. Organization: The MITRE Corporation, McLean, VA
  9. References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov>
  10. Date: Thu, 5 Nov 1992 05:17:45 GMT
  11. Lines: 66
  12.  
  13. In article <1992Nov5.014143.15635@newshost.lanl.gov> jlg@cochiti.lanl.gov (J. Giles) writes:
  14. >In article <Bx7oAz.7Lp@mentor.cc.purdue.edu>, hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
  15. >|> [...]
  16. >|> Now a knife, or a gun, can be used for good or evil.  They can cause
  17. >|> accidents.  Likewise with pointers.
  18. >
  19. >Yes, but pointers should be available for *voluntary use* - not 
  20. >by compulsion.  They are *not* adequate substitutes for arrays.
  21. >Explicit pointers are *not* needed for dynamic memory allocation.
  22. >I would prefer *not* to have to use them for simply connected
  23. >recursive data structures (like acyclic lists or trees).
  24.  
  25. As many have pointed out, C has arrays.  When you prefer to use an array
  26. in C, you can and should.  To quote the bards K&R, "pointers are not arrays".
  27. (If they didn't say that, some other wise soul surely has.)
  28.  
  29. As for using pointers for dynamic memory access or dynamically extensible
  30. data structures -- "a rose is a rose by any other name".  In Pascal and 
  31. Modula2 they're called typed pointers.  In Ada they're access types.  In
  32. Lisp and Prolog, you're out of luck -- you're stuck with lists/trees and
  33. garbage collection.
  34.  
  35. Remember, I (and I think others too) am not defending K&R C.  I much prefer
  36. the typing of pointers made handy in ANSI C to the untyped hash they made
  37. in K&R C.  I have little trouble with any sort of pointer "spaghettiness" 
  38. in ANSI C.  And if that's not enough for you, there's always C++.  There
  39. you can use other peoples' classes for all that sort of thing and keep 
  40. your phalanges as clean as you like.
  41.  
  42. >
  43. >Pointers are the GO TO of data structuring.  They are used to create
  44. >spaghetti data structures in the same way GO TO is used to create
  45. >spaghetti code.  If it's at all possible to avoid using them, don't
  46. >use them.  As with GO TO, you only use 'em when you GOT TO.  Also,
  47. >as with GO TO, there are ways to make your use more structured if
  48. >you *must* use them.
  49.  
  50. In my opinion, no language leads to worse spaghetti-like data structures 
  51. than Lisp, a language without pointers and dependent on garbage collection
  52. to do for the programmer what s/he prefers not to do.  That's swell.  For
  53. those (like yourself) who prefer to let the language dictate efficiency,
  54. I suggest you steer clear of C.  That is especially true if you're unable
  55. to devise clean tight data structures.
  56.  
  57. But don't attempt to condemn a programming language which has become the
  58. lingua franca of the workstation world simply because it isn't all things
  59. to all people.
  60.  
  61. >   First: in both, you should avoid having loops.  In the case of GO TO,
  62. >   you should try not to branch backward.  In the case of pointers, you 
  63. >   should try to avoid cyclic data structures.
  64.  
  65. [a great deal of irrelevant goto discussion deleted]
  66.  
  67. If the justification for avoiding gotos appears to you to be equivalent 
  68. to the rationale behind pointer use, you really should get away from C as 
  69. quickly as possible.
  70.  
  71. C isn't for everybody, just as Lisp is not.  Each has its uses, and each
  72. cannot supplant the other.
  73.  
  74. -- 
  75.  
  76. | Randy Crawford        crawford@mitre.org        The MITRE Corporation
  77. |                                                 7525 Colshire Dr., MS Z421
  78. | N=1 -> P=NP           703 883-7940              McLean, VA  22102
  79.