home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #16 / NN_1992_16.iso / spool / comp / lang / eiffel / 1016 < prev    next >
Encoding:
Internet Message Format  |  1992-07-29  |  2.2 KB

  1. Path: sparky!uunet!mcsun!uknet!root44!hrc63!mrcu!paj
  2. From: paj@uk.co.gec-mrc (Paul Johnson)
  3. Newsgroups: comp.lang.eiffel
  4. Subject: Re: Small methods ! Why ?
  5. Message-ID: <1857@snap>
  6. Date: 29 Jul 92 07:31:28 GMT
  7. References: <13303@ns-mx.uiowa.edu>
  8. Reply-To: paj@uk.co.gec-mrc (Paul Johnson)
  9. Organization: GEC-Marconi Research Centre, Great Baddow, UK
  10. Lines: 47
  11.  
  12.  
  13. >I came across the following sentence in a paper:
  14.  
  15. >"Good object oriented programming style seems to encourage the
  16. >use of many small methods."
  17.  
  18. >Why is this so ?
  19.  
  20. One of the major goals of OO programming is flexibility.  A big
  21. function can only be modified by delving deep into its code.  The only
  22. way of reusing a part of its functionality is by copying the code and
  23. changing bits.  On the other hand, lots of little functions can be
  24. modified by replacing one function with another.  Dynamic binding
  25. (what C++ calls `virtual functions) provides a way of doing this in a
  26. controlled manner.  Hence an OO program with lots of little functions
  27. is more flexible and hence more mainainable.
  28.  
  29. >This programming style leads to code (and functionality)
  30. >that is widely dispersed.  Therefore, a maintainer may have to
  31. >use sophisticated class browsers to understand the code even for
  32. >a fairly simple task, simply because it is widely dispersed.
  33.  
  34. One of the major concepts in Eiffel is that you should not have to
  35. delve into the code to understand a piece of functionality.  The class
  36. documentation (including the short-flat form with its preconditions
  37. and postconditions) should make this clear.
  38.  
  39. If it does become necessary to delve into a function, one that has a few
  40. lines of code which call other functions is more understandable than a
  41. complex mess of loops and local variables.
  42.  
  43. >This style seems to be quite prevalent among C++
  44. >programmers.
  45.  
  46. >Is it so with programmers in other OO languages as well ?
  47.  
  48. Yes.  Even more so with Eiffel.
  49.  
  50. Paul.
  51.  
  52.  
  53.  
  54. -- 
  55. Paul Johnson (paj@gec-mrc.co.uk).        | Tel: +44 245 73331 ext 3245
  56. --------------------------------------------+----------------------------------
  57. These ideas and others like them can be had | GEC-Marconi Research is not
  58. for $0.02 each from any reputable idealist. | responsible for my opinions
  59.