home *** CD-ROM | disk | FTP | other *** search
/ ftp.umcs.maine.edu / 2015-02-07.ftp.umcs.maine.edu.tar / ftp.umcs.maine.edu / pub / WISR / wisr6 / proceedings / ascii / beidler2.ascii < prev    next >
Text File  |  1993-10-19  |  11KB  |  240 lines

  1.  
  2.  
  3.  
  4.  
  5.             Iterators:  Opportunities  Lost,  Lessons  Learned.
  6.  
  7.  
  8.  
  9.                                                John Beidler
  10.  
  11.  
  12.  
  13.                                       Computing Sciences Dept.
  14.  
  15.                                          University of Scranton
  16.  
  17.                                           Scranton, PA 18510
  18.  
  19.                                            Tel:  (717) 941-7446
  20.  
  21.                                       Email:  beidler@cs.uofs.edu
  22.  
  23.  
  24.  
  25.                                                   Abstract
  26.  
  27.  
  28.     Iterators, as defined by Booch, have restricted the potential that is available through itera-
  29. tors to encourage software reusability. Iterators present a rich opportunity for to improve the
  30. reusability of generics, but this opportunity requires some trade offs between making iterators
  31. general and keeping them usable.  It also requires the development of educational material on
  32. how to make the best use of iterators.
  33.  
  34.  
  35. Keywords: Reuse, data structure components, iterators, generics
  36.  
  37.  
  38. Workshop Goals: Designing reuseable components and tools, teaching reuse.
  39.  
  40.  
  41. Working Groups: Low level(intermediate level) reuse, reuse education
  42.  
  43.  
  44.  
  45.                                                   Beidler- 1
  46.  
  47.  
  48. 1      Background
  49.  
  50.  
  51.  
  52. Booch's book Software  Components  with  Ada, established a standard for the encapsulation
  53. of objects in Ada packages. Normally, the operations on objects are classified into two categories,
  54. constructors and selectors. However, Booch expanded upon this classification by including a third
  55. category, iterators. An iterator is defined by Booch as "an operation that permits all parts of an
  56. object  to  be  visited".  Throughout  his  book  Booch  addresses  the  development  of  iterators  over
  57. various objects, but due to the nature and goals of the book, the construction and potentialuses
  58. of iterators in Ada packages are never fully developed.
  59.  
  60.  
  61. We take a slightlydifferent view of iterators.  Instead of viewing iterators as a third category of
  62. operations on objects, we view iterators as an intermediate building block,  a reusable tool,  that
  63. may be used to fabricate constructors and selectors.
  64.  
  65.  
  66. Unfortunately, Booch's  book  established  a  precedent  on  how  iterators  are  viewed  by  the  Ada
  67. community. This precedent is continued with another set of commercially available components,
  68. the GRACE components from EVB Software Engineering.  As such, both the Booch and GRACE
  69. components  contain  at  most  one  iterator  per  data  structure.  In  fact, there  are  several  possible
  70. iterators for most data structure. For example, both the Booch and GRACE components supply
  71. only one iterator for binary trees.  The iterator is a depth first iterator.  It is easy to demonstrate
  72. that there are at least 14 standard variations ofdepth first iterators and several other families of
  73. binary tree iterators.
  74.  
  75.  
  76. In several papers we built upon the concept presented by Bo och and demonstrates that some care
  77. must be taken to build iterators in order to makethem more versatile to potential users of the
  78. packages that contains them. The result of providing more useful iterators a potentially greater
  79. amount of low and intermediate level software reuse.  Iterators also encourages the decomposition
  80. of certain algorithms in a standardized fashion leading to improved software readability.
  81.  
  82.  
  83. The full use of iterators stand as a lost opportunity to the Ada83 community. Perhaps it is time to
  84. revisit this subject and, perhaps, learn some lessons about the encapsulation of reusable components
  85. and tools that may provide insight intoreuse at other levels.
  86.  
  87.  
  88. Further,  Ada9X presents us with new opportunities.  In particular,  many of the new features in
  89. Ada9X provide new approaches to encapsulation that allow us, under many circumstances,to avoid
  90. the use of generics and limited private typ es,two features that are at the heart of safe encapsulation
  91. in Ada83.  How will these new features simplify the client's use of encapsulated components and
  92. tools?
  93.  
  94.  
  95.  
  96. 2      Position
  97.  
  98.  
  99.  
  100. We propose that Booch's view of iterators should be abandoned for two reasons.  First, the view,
  101. by being too narrow, discourages the study of iterator, hence a lost opportunity that might provide
  102. some insight into low leveland intermediate level reuse issues.  Specifically, we feel that a study
  103. of the issues surrounding the encapsulation of iterators mayprovide some insight into the general
  104. issues of encapsulating reusable software.
  105.  
  106.  
  107. Second, as various generic components, and data structure components in particular, are redesigned
  108. to take full advantage of Ada9x,  we should review the features that are available in the language
  109.  
  110.  
  111.  
  112.                                                          Beidler- 2
  113.  
  114.  
  115. to properly support better and more efficient reusability.  The potential richness of the study of
  116. how we should encapsulate iterators and provide other means of access and manipulating objects
  117. within a structure might provide us with additional insight into other, higher level, reuse.
  118.  
  119.  
  120. A case worth analyzing is the issue of appropriate encapsulation of a sufficient collection of binary
  121. tree iterators that will assist clients when they reuse a data structure.  We have studied four families
  122. of binary tree iterators:
  123.  
  124.  
  125.  
  126.     fflDepth First Iterators
  127.  
  128.     fflBreadth First Iterators
  129.  
  130.     fflBinary Search Iterators
  131.  
  132.     fflPriority Queue Directed Iterators
  133.  
  134.  
  135.  
  136. An analysis of these families of iterators provides insight into the trade-offs that must be made
  137. between generality and usability of anencapsulated iterator.  If an iterator is encapsulated as a
  138. generic procedure,  within a generic package,  what guidelines might be established regarding the
  139. use of the formal instantiation parameters,the formal parameters of the instantiating procedure(s),
  140. and the iterator's formal parameters?
  141.  
  142.  
  143. An equally important issue is the issue of training software developers to properly use iterators. It
  144. has been our experience that clients might have toreorganize their (low level) design, or at least
  145. restructure parts of algorithms, to make use of an encapsulated iterator.  However, with consistent
  146. iterator design guidelines, we may be able to easily educate software developers regarding how to
  147. redesign algorithms to take advantage of encapsulated iterators.  For the last two yearswe have
  148. experimented with teaching about the use of iterators, but withp oor success,in an advanced data
  149. structures course. We have llearned that good iterator design is not enough, it mustb e combined
  150. with appropriate education in how to design with reuse in mind.  We plan to do include a balanced
  151. presentation that addresses both side, designing reusable software and exploiting reusable software,
  152. this in the Fall as part of an advanced data structure course.
  153.  
  154.  
  155. In Ada 83, we have adopted the following design guidelines for the construction of iterators:
  156.  
  157.  
  158.  
  159.     fflIf the iterator allows the instantiating procedure to have an iterator control, frequently called
  160.        the Continue parameter, the control should be passed as an in out parameter and given an
  161.        initial value by the iterator.
  162.  
  163.     fflA pass through parameter must be included to allow the client to pass information between
  164.        instantiating procedures and the client procedure that uses the instantiated iterator.
  165.  
  166.     fflAre the positions and use of parameters consistent?  Consistent within the encapsulation of
  167.        an iterator?  Consistent across iterators within other packages?
  168.  
  169.     fflClients  must  be  provided  with  guidelines  regarding  the  safe  and  efficient instantiation  of
  170.        generic procedures that encapsulate iterators.
  171.  
  172.  
  173.  
  174. 2.1     Comparison
  175.  
  176.  
  177.  
  178. As we move to Ada9x (or C++), how do we buildup on the lessons learned about iterators and
  179. take full advantage of the new opp ortunities available in Ada9x?  Even if the issues of iterators
  180. are redressed in the commercially available comp onent sets, can we expect other advances as well?
  181. Through an ARPA Software Engineering and Ada Education Grant we build a set of iterators in
  182.  
  183.  
  184.                                                          Beidler- 3
  185.  
  186.  
  187. Ada83 that address the issue of iterators, as well as several other issues that have been overlooked
  188. in the popular commercial component sets.
  189.  
  190.  
  191. Another issue not addressed by the commercial components is the issue of "in  place" access to
  192. objects within a structured object.  For example, typical access to an object within a structured
  193. object is through copy and modify functions and procedures. Yet "in place" access is easy to supply,
  194. and provide a efficient and safe means of changing the value of an object within an object.
  195.  
  196.  
  197. To create an analogy (perhaps a bit extreme), how does a dentist fixa cavity in a tooth?  Does
  198. he remove the tooth,  fix it,  then put it back?  Of course not,  he does not remove the tooth, he
  199. fixes it (changes its value) while leaving the tooth where it belongs.  If Booch and EVB had a data
  200. structure called "gums" that contained objects called "tooth", they would pull the tooth out, fix
  201. it, and replace it, which is not an efficient way to proceed, rather than providing "in place" access
  202. to the tooth.
  203.  
  204.  
  205.  
  206. 2.2     Ada9X and Iterators
  207.  
  208.  
  209.  
  210. The  object  oriented  features  in  Ada9X provide  us  with  an  opportunity  to  experiment  with  the
  211. encapsulation of reusable components without the use of generics and limited private types. Many
  212. current reuse problems center on misunderstandingsby clients of the need for limited private types.
  213. Finalization in Ada9X provides a safe way ofusing private types in Ada9X, when similar safety
  214. was accomplished in Ada83 only through the use of limited private types.
  215.  
  216.  
  217. Clients also faced problems with generic instantiation in Ada83.  Specifically, the specific placement
  218. of instantiations caused various problems with a number of Ada compilers. With the judicious use of
  219. tagged types and Access parameters, various data structure components may be encapsulated
  220. in Ada9X in a non-generic package! Further,instead of using generic procedures with the package
  221. to encapsulate iterators, iterators may be encapsulated as non generic procedures, using a tagged
  222. type that may be polymorphed to pass client information to and from theclient's procedure that is
  223. controlled by the iterator. The client's procedure may be passed to the iterator as an Access type.
  224.  
  225.  
  226.  
  227. 3      Biography
  228.  
  229.  
  230.  
  231. John Beidler is a Professor of Computer Science at the University of Scranton.  He served there
  232. as department chair for overfifteen years before stepping down as chair to spend more time on
  233. research.  He currently serves as Director of the Masters Program in Software Engineering.  His
  234. research interests are in programming support environments, software reusability, data structures
  235. and algorithms, and computational complexity.
  236.  
  237.  
  238.  
  239.                                                          Beidler- 4
  240.