home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / misc / 3691 < prev    next >
Encoding:
Internet Message Format  |  1992-11-15  |  4.6 KB

  1. Path: sparky!uunet!know!cass.ma02.bull.com!think.com!rpi!usc!zaphod.mps.ohio-state.edu!wupost!udel!pervert!louie!balin.cis.udel.edu!carroll
  2. From: carroll@balin.cis.udel.edu (Mark C. Carroll)
  3. Newsgroups: comp.lang.misc
  4. Subject: Re: Pointers
  5. Message-ID: <1992Nov15.195732.8948@udel.edu>
  6. Date: 15 Nov 92 19:57:32 GMT
  7. References: <id.6HVU.OC@ferranti.com> <1992Nov12.200950.8846@newshost.lanl.gov> <Bxnqv5.J71@mentor.cc.purdue.edu>
  8. Sender: usenet@udel.edu (USENET News Service)
  9. Organization: University of Delaware, Newark
  10. Lines: 91
  11. Nntp-Posting-Host: balin.cis.udel.edu
  12.  
  13. In article <Bxnqv5.J71@mentor.cc.purdue.edu> hrubin@pop.stat.purdue.edu (Herman Rubin) writes:
  14. >In article <1992Nov12.200950.8846@newshost.lanl.gov> jlg@cochiti.lanl.gov (J. Giles) writes:
  15. >
  16. >            .......................
  17. >
  18. >>C.A.R. Hoare proved that the concepts of pointers and GOTOs are
  19. >>*isomorphic* - which is a lot stronger than a mere analogy.  The
  20. >>consequence of this observation is that *any* valid argument against
  21. >>GOTOs is equally valid against pointers.  Period.  As I keep saying,
  22. >>you cannot do any coding at all without GOTOs, it's just that most 
  23. >>of the ones you use are hidden under an interface (IF/ELSE, DO/ENDDO,
  24. >>SELECT/CASE, procedure calls, etc.) which capture the *specific* semantics
  25. >>of the flow control the user has in mind.  The same kinds of interfaces
  26. >>need to be designed and applied to data structures to eliminate *raw*
  27. >>pointer instances.
  28. >
  29. >Why do some people find it necessary to hide simple devices under 
  30. >interfaces?  The insistence on the use of these interfaces is like
  31. >the joke about the mathematician who pours the water out of the bucket
  32. >and turns off the stove to reduce the problem to the previous case.
  33. >
  34.  
  35. Why do people find the need to destroy abstractions in favor of
  36. incomprehensible low-level implementations?
  37.  
  38. In virtually any computer program, there is a conceptual data
  39. structure, such as a list, a tree, a graph, a stream, etc. The
  40. conceptual data structure has some set of natural operations and
  41. properties. When the conceptual data structure is mapped into an
  42. implementation, the low-level implementation of the structure does not
  43. necessarily preserve the properties of the structure. The idea of
  44. interfaces is to present the _conceptual_ data structure, and not the
  45. implementation data structure. 
  46.  
  47. If you're a half-decent programmer, there is *no* performance penalty
  48. for building the structure behind an interface. But all users of the
  49. structure can work with the structure as if it is the conceptual
  50. structure, rather than the implementation structure.
  51.  
  52. For example (in C), if you need to implement a list, you can create a
  53. structure:
  54.  
  55. typedef struct _list {
  56.    value v;
  57.    struct _list *next;
  58. } *list;
  59.  
  60. Then, all of your users have to muck with pointers. They have to be
  61. careful to not create cycles, and to deallocate entries at the right
  62. time, etc.
  63.  
  64. On the other hand, you can present an interface, with a set of operations:
  65.  
  66.     list new_list()
  67.     value value_at_cursor(list);
  68.     void cursor_tobegin(list)
  69.     void cursor_forward(list);
  70.     void insert_at_cursor(list,value)
  71.     value remove_value_at_cursor(list);
  72.     void destroy_list()
  73.  
  74. This interface has all of the properties of the conceptual structure
  75. that the previous implementation models. But it is *guaranteed* to
  76. preserve those properties. It also relieves the user of the structure
  77. from having to deal with the grunginess of the implementation model.
  78. And finally, if I decide that my structure isn't a good implementation
  79. model, I can *transparently* change it - my users don't even realize
  80. that it's changed!
  81.  
  82. (An example of all this comes from my current project. I use a
  83. heirarchical symbol table. I initially implemented the table as a
  84. hashtable. After building 20,000 lines of code on top of this, I
  85. unexpectedly discovered that most of the time, each level of the
  86. heirarchy contained less than 10 elements - so my hashtable was a very
  87. poor way to implement it - it was slower than the alternatives, and
  88. wasted an enormous amount of memory. So I changed the implementation
  89. of use association lists. I didn't have to rewrite a *single* line of
  90. code outside of my symbol table implementation, because my code used
  91. the interface to the type, and the properties of the type didn't change
  92. a bit.
  93.  
  94. In addition, I didn't pay *any* performance penalty for implementing my
  95. datatype behind an interface.)
  96.  
  97.  
  98.     <MC>
  99. -- 
  100. || Mark Craig Carroll: <MC>     ||"I prize the cloudy, tearing sky,
  101. || Univ of Delaware, Dept of CIS|| for the thoughts that flap and fly.
  102. || Grad Student/Labstaff Hacker || For staying in and reading by.
  103. || carroll@udel.edu             || For sitting under" -Karen Peris
  104.