home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 18125 < prev    next >
Encoding:
Text File  |  1992-12-17  |  6.0 KB  |  156 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!psinntp!uu0465!andrew
  3. From: andrew@tagsys.com (Andrew Gideon)
  4. Subject: Complexity in the eyes...V2.0
  5. Message-ID: <1992Dec17.042207.8150@tagsys.com>
  6. Organization: TAG Systems inc.
  7. Date: Thu, 17 Dec 1992 04:22:07 GMT
  8. Lines: 146
  9.  
  10.  
  11. Almost a month ago, I tried to start a new thread on the topic
  12. of "complexity".  I assume that everyone agrees that a goal of
  13. software engineering should be the reduction of complexity.  But
  14. what I have recently seen is that the metrics by which complexity
  15. is measured appear to be very subjective.
  16.  
  17. There were some very interesting comments, but - perhaps because I
  18. fell way behind in my net-readership - the thread died a quiet
  19. death.  I'd like to try again, in this case with a specific example.
  20.  
  21. First, however, I'd like to reply to some of the postings and email
  22. that I received.
  23.  
  24. 1.    karl@BofA.com (Karl Nicholas) asks why a consumer of classes
  25.     would be peeking around the internals of those classes, 
  26.     and any possible superclasses.
  27.  
  28.     A lot of people (well...a few) provided answers.  I provided
  29.     a couple of simplisitic ones (I was rushed!): debugging and
  30.     understanding.
  31.  
  32.     maxtal@extro.ucc.su.OZ.AU (John MAX Skaller) agreed with the
  33.     "understanding" issue.
  34.  
  35.     I still think, however, that good documentation would solve
  36.     that problem.  The fact that I've never seen documentation
  37.     of sufficient quality may be significant, however.  Perhaps
  38.     some nifty tool which reads class definitions provides a
  39.     "flattened" interface?
  40.  
  41.     gregc@eagle.fsl.noaa.gov (Greg Compestine), BTW, 
  42.     brought up the same point.  He wants ObjectWorks for
  43.     xmas...I'll be evaluating it shortly.  Maybe it'll turn out
  44.     to be that nifty tool.
  45.  
  46. 2.    I cannot decide quite how to take the answer from
  47.     rmartin@thor.Rational.COM (Bob Martin).  He suggested
  48.     gathering 10 engineers, provide half with a solution one
  49.     way and half with a solution the other way.  Then measure
  50.     how long it takes for them to make a modification.
  51.  
  52.     If I had a lot of time and 10 engineers, it would certainly
  53.     be an interesting experiment.  Unfortunately, I have neither.
  54.  
  55.     My *opinion* is that I have been better able to respond to
  56.     shifting requirements than has been my coworker who prefers
  57.     less inheritance, dispatching, and other forms of modularization
  58.     (is that a word?).  But his opinion may differ.
  59.  
  60. 3.    rknazik@x102a.ess.harris.com (knazik bob) suggested a limit
  61.     of inheritance levels to be used (he proposed four).  This
  62.     bothers me.  It is (1) arbitrary and (2) difficult in practice
  63.     to do as the user of a class is STILL required to figure out
  64.     how many of these levels are already "used".
  65.  
  66.     Also, it ignores the cases where some class within a heriarchy
  67.     must be fragmented.  Maybe I have a Hand class, but I need a
  68.     LeftHand class.  I can fragment the Hand into LeftHand and 
  69.     RightHand, and then reconstruct Hand using MI.  But if there
  70.     are enough levels of inheritance below Hand (and how would 
  71.     one know this!), this fragmentation is prevented.
  72.  
  73. Anyway, this is getting long, and I want to write my example up.
  74. My example is a problem and two solutions: mine and my coworker's.
  75. The question that I have is: which do you (plural) prefer (for any
  76. reasons), and why?
  77.  
  78. The problem: moving errors around.  This includes moving errors
  79. between applications, but it also includes the conventional problem
  80. of passing errors up through a sequence of procedure calls.
  81.  
  82. My solution (well, I don't claim that the original idea was mine):
  83. an error stack class.  This permits a function to push messages
  84. onto the stack as the error is propogated upwards.  An error
  85. stack might contain:
  86.  
  87.     Save of dohickey failed
  88.  
  89.     Unable to write dohickey.dat
  90.  
  91.     disk full
  92.  
  93. The lower levels contain greater detail on the failure, as they
  94. are generated closer to the actual fail point.  The higher levels
  95. contain additional context information, as they know more of "why"
  96. the failed operation was requested.
  97.  
  98. Because this is a class, I was easily able to add methods to
  99. support transporting these between applications.  The class also
  100. supports code like:
  101.  
  102.     ErrorStack err;
  103.  
  104.     if (!(err = foo()))
  105.     {
  106.         //
  107.         // Take some failure action
  108.         //
  109.         err.push("More error info");
  110.         return(err);
  111.     }
  112.  
  113. [For those that find this too terse (like me), it also
  114.  provides methods like isOk(), isBad(), etc.  That use of a
  115.  not operator is a convention, but I find "if ((err = foo()).isBad())"
  116.  more obvious.]
  117.  
  118. To me, this is simple.  It is simple to use merely as a way to
  119. return error/success.  It is simple to get the outer-most error
  120. (or the inner-most).  I also provided an iterator for those hardy
  121. souls who want to access all the messages in the stack.
  122.  
  123. [I also provided a log method.  This one feature alone was a great aid
  124.  on those all-to-frequent occasions when I had to debug a runtime
  125.  problem.]
  126.  
  127. My coworker thinks this complex.  He'd prefer returning an integer.
  128. The integer is an offset into an array of error messages.  If there
  129. are multiple modules (when are there not?!), use one byte as a module
  130. number to determine the specific array, and another byte as the offset.
  131.  
  132. He doesn't even want this encapsulated in a class, as that would
  133. "make it more complex."  He sites as evidence that - at our last
  134. location - few people wanted to use the error stack class.  I
  135. attribute this to lack of documentation (I was not contracted to
  136. provide reusable tools there, so I never did get to build decent 
  137. documentation) and publicity.  Also, my biased opinion is that too
  138. few people even think about errors; some are still happy with global
  139. error number variables.  Error handling behavior is "stuck on" rather
  140. than "designed in".
  141.  
  142. So...what is the opinion of the net?
  143.  
  144.     - Andrew Gideon
  145.  
  146.  
  147. === 
  148.  -----------------------------------------------------------
  149. | Andrew Gideon              |                              |
  150. | Consultant                 |                              |
  151. |                            |   TAG Systems inc.           |
  152. | Tel: (201) 890-7189        |   D2-181 Long Hill Road      |
  153. | Fax: (201) 890-1581        |   Little Falls, N.J., 07424  |
  154. | andrew@tagsys.com          |                              |
  155.  -----------------------------------------------------------
  156.