home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / misc / 3499 < prev    next >
Encoding:
Internet Message Format  |  1992-11-05  |  2.4 KB

  1. Path: sparky!uunet!gumby!yale!yale.edu!think.com!barmar
  2. From: barmar@think.com (Barry Margolin)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: Pointers
  5. Date: 5 Nov 1992 18:58:16 GMT
  6. Organization: Thinking Machines Corporation, Cambridge MA, USA
  7. Lines: 35
  8. Message-ID: <1dbqs8INN7qo@early-bird.think.com>
  9. References: <1992Nov4.093545.15950@rdg.dec.com> <Bx7oAz.7Lp@mentor.cc.purdue.edu> <1992Nov5.014143.15635@newshost.lanl.gov>
  10. NNTP-Posting-Host: telecaster.think.com
  11.  
  12. In article <1992Nov5.014143.15635@newshost.lanl.gov> jlg@cochiti.lanl.gov (J. Giles) writes:
  13. >   Second: in both, you should avoid aliasing.  In the case of GO TO,
  14. >   you should avoid branching to the same label for many disparate
  15. >   reasons.  In the case of pointers, you should try to avoid have
  16. >   two pointers to the same thing *at all*.
  17.  
  18. That's a silly guideline.  The most common reason to use pointers is
  19. precisely *because* you need multiple references to the same data.  In
  20. object-based programming, an object may be in different relationships with
  21. other objects, and relationships are usually implemented as pointers
  22. between objects.  For instance, in a family tree model, a person might have
  23. pointers to its parents, children, and siblings; any particular person is
  24. likely to be referenced by the children array of two parents and a parent
  25. pointer of some children.
  26.  
  27. Your guideline suggests that the main reason for using pointers is to avoid
  28. copying data (e.g. passing arguments by reference by passing a pointer).
  29. While pointers are certainly useful for this (in languages that don't
  30. provide better mechanisms, such as C++'s references), I hardly consider it
  31. the raison d'etre of pointers.
  32.  
  33. In another article, someone pointed out that the most spaghetti structured
  34. code tends to be Lisp, which doesn't have pointers.  While it's true that
  35. Lisp doesn't have distinct pointer values, in some sense every value is
  36. conceptually a pointer value, because of Lisp's object-based nature (most
  37. Lisp dialects allow optimizations for numeric values that that allow them
  38. to be treated as non-objects, though).  The only difference between Lisp
  39. and other languages in this regard is that Lisp doesn't have an explicit
  40. dereference operator, as dereferencing happens automatically.  The Lisp
  41. expression (car a) is analogous to the C expression (cons *)a->car.
  42. -- 
  43. Barry Margolin
  44. System Manager, Thinking Machines Corp.
  45.  
  46. barmar@think.com          {uunet,harvard}!think!barmar
  47.