home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16722 < prev    next >
Encoding:
Text File  |  1992-11-21  |  4.2 KB  |  120 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!psinntp!uu0465!andrew
  3. From: andrew@tagsys.com (Andrew Gideon)
  4. Subject: Re: Complexity in the eyes of the beholder?
  5. Message-ID: <1992Nov20.215332.28848@tagsys.com>
  6. Sender: andrew@tagsys.com (Andrew Gideon)
  7. Organization: TAG Systems inc.
  8. References: <1992Nov18.024553.24081@tagsys.com> <1992Nov19.221923.12282@BofA.com>
  9. Date: Fri, 20 Nov 1992 21:53:32 GMT
  10. Lines: 108
  11.  
  12.  
  13. In article <1992Nov19.221923.12282@BofA.com> karl@BofA.com (Karl Nicholas) writes:
  14. >In article <1992Nov18.024553.24081@tagsys.com> andrew@tagsys.com (Andrew Gideon) writes:
  15. >>
  16. >> ...
  17. >>
  18. >>To me, I achieve my goal (except when I violate my own
  19. >>rules - which does happen more frequently than I like {8^).
  20. >>But this coworker claims that the many levels are too
  21. >>complex to follow.  In trying to understand a class, he
  22. >>is forced to recurse too frequently and too far.
  23. >>
  24. > But why is he recursing into the subclasses? It would seem
  25. >to me that he should be taking the classes that he deals
  26. >with for what they are, and not worry about how they work.
  27. >
  28.  
  29. There are two reasons for which one might recurse "downward":
  30.  
  31. 1.    Lack of understanding of the class being used
  32.     (ie "what does this method do?")
  33.  
  34. 2.    Looking for a bug
  35.  
  36. The frequency of reason 1 can be reduced with good documentation.
  37. I doubt that it can be eliminated completely.  I am full of praise
  38. for the Rogue Wave documentation, for example.  But occasionally,
  39. I get a better understanding of behavior - and we are talking 
  40. merely about *interface* behavior here - by looking through
  41. the code.
  42.  
  43. The frequency of reason 2 can be reduced by writing code with
  44. no bugs {8^)
  45.  
  46. BTW, the term "recursing" may be unfortunate, in that it does
  47. gloss over a significant cause of difficulty here: virtual
  48. functions.  Often the "recursion" is actually away from an
  49. inheritance graph root.  Further, the actual method being invoked 
  50. may not be discernible through static examination of the code.
  51. Multiple Inheritance also adds to the complexity of the
  52. "recursion" process.
  53.  
  54. I know that I am arguing his side here.  As I said, I do
  55. see his point.  
  56.  
  57.  
  58. More on reason 1:
  59.  
  60. void foo(SomeArbitraryClass *obj)
  61. {
  62.     obj.doSomething();
  63. }
  64.  
  65. What does foo() accomplish?  If I (the class designer of
  66. SomeArbitraryClass) do my job well, the action of foo() should be 
  67. expressible as a single function, regardless of the actual 
  68. implementation of doSomething() which is selected.
  69.  
  70. But...can I (still the class designer) guarantee this?  Perhaps
  71. someone else has a subclass of SomeArbitraryClass which defines
  72. a doSomething() such that the documented function of foo() would
  73. not be correct for objects of that new class.
  74.  
  75. Perhaps the words that I choose to describe the function of
  76. foo() have a different meaning to the reader of the documentation.
  77.  
  78. I just do not know the answer to this.  Is it merely (merely?!?!)
  79. a question of "clear design" (ie principle of least astonishment)
  80. and documentation?
  81.  
  82.  
  83. >  I think the tradeoff is speed of code verses modularity.
  84. >many classes supports modularity, which from a systems
  85. >standpoint is preferable, where larger classes supports
  86. >speed of execution, which from a user standpoint is
  87. >preferable. I try to incorporate as much modularity
  88. >as possible until the speed for the user becomes a problem.
  89. >
  90.  
  91. Ha!  I'm not even thinking about considering the act of
  92. going near the cabinet in which resides this can of worms.
  93.  
  94. Besides, with good compilers and careful inlining... {8^)
  95.  
  96.  
  97.  
  98. Thanks...
  99.  
  100.     Andrew Gideon
  101.  
  102. P.S.    I needed a word in the above discussion that I
  103.     could not recall.  I used "inheritance graph
  104.     root".  What I wanted was a node in a directed
  105.     graph (acyclic) which has edges leading only outward.
  106.     This node represents a class which is a base class
  107.     of n (n>=0) other classes, and which has exactly 0
  108.     base classes of its own.  What is a word for
  109.     this?
  110.  
  111. === 
  112.  -----------------------------------------------------------
  113. | Andrew Gideon              |                              |
  114. | Consultant                 |                              |
  115. |                            |   TAG Systems inc.           |
  116. | Tel: (201) 890-7189        |   D2-181 Long Hill Road      |
  117. | Fax: (201) 890-1581        |   Little Falls, N.J., 07424  |
  118. | andrew@tagsys.com          |                              |
  119.  -----------------------------------------------------------
  120.