home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #20 / NN_1992_20.iso / spool / comp / lang / ada / 2616 < prev    next >
Encoding:
Text File  |  1992-09-15  |  7.1 KB  |  136 lines

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!haven.umd.edu!darwin.sura.net!Sirius.dfn.de!Urmel.Informatik.RWTH-Aachen.DE!vivaldi!pk
  3. From: pk@rwthi3.informatik.rwth-aachen.de (Peter Klein)
  4. Subject: Re: MI - clutching at straws
  5. Message-ID: <1992Sep15.140840.3405@Urmel.Informatik.RWTH-Aachen.DE>
  6. Sender: news@Urmel.Informatik.RWTH-Aachen.DE (Newsfiles Owner)
  7. Nntp-Posting-Host: vivaldi
  8. Reply-To: pk@rwthi3.informatik.rwth-aachen.de
  9. Organization: Lehrstuhl fuer Informatik III, RWTH Aachen, Germany
  10. References: <EACHUS.92Sep14151942@Dr_No.mitre.org>
  11. Date: Tue, 15 Sep 92 14:08:40 GMT
  12. Lines: 122
  13.  
  14. In article 92Sep14151942@Dr_No.mitre.org, eachus@Dr_No.mitre.org (Robert I. Eachus) writes:
  15. >In article <1992Sep9.142434.3940@Urmel.Informatik.RWTH-Aachen.DE> pk@rwthi3.informatik.rwth-aachen.de (Peter Klein) writes:
  16. >
  17. > > Unfortunately, your arguments don't hold in my example, where several
  18. > > extensions of the same base type are combined. The resulting type is
  19. > > essentially the base type augmented by an arbitrary subset of the possible
  20. > > extensions. The problems you mentioned cannot arise in this context.
  21. > > Furthermore, it is pretty awkward to simulate such behaviour without MI.
  22. >
  23. >    But it is exactly that case...the (base) type is extended with lists
  24. >and trees, and then these extensions are combined.  (It is hard not to
  25. >use nasty words to relieve frustration at this point, but I know that
  26. >this is a hard enough to understand mechanisms like type extension and
  27. >inheritance, and the subtile differences in mechanisms discussed here
  28. >tend to rapidly convert any brain into jelly, but bear with me.)
  29. >  
  30. Well, either you didn't understand my example or I didn't understand
  31. yours :). Here's my understanding of what you said: You have some
  32. base type, say X. Now you make up lists and trees which *contain* entries
  33. of type X. Right? But then, neither the list nor the tree class are
  34. subtypes of X. They are containers with no common base class and therefore
  35. cannot be "merged" in my proposal.
  36.  
  37. The other possibility would be that your base class is a container class
  38. like lists, and then you make subtypes for trees and sets. In this case,
  39. it is first of all doubtful that inheritance should be used at all to
  40. design this (since the inheritance is completely on the implementation
  41. part; this is more likely a simple import). Anyway, if you insist to do
  42. so, you could make a class then which is both a set and a tree. But who
  43. would want to do so?
  44.  
  45. >    Part of the problem is semantic.  I think Tucker will be glad to
  46. >explain to you how Ada implements multiple inheritance, while most of
  47. >us use MI to mean something other than generic instantiation, but
  48. >Tucker does have a point.  The Ada 9X mechanisms are safer and more
  49. >general than those offered by most instances of MI, but it does
  50. >require more thinking up front by the designer of a mix-in.
  51. >
  52. > > Not true. Inheritance is the more powerful feature. Dynamical binding cannot
  53. > > be done with genericity; you'll never get true polymorphism without
  54. > > inheritance. But I don't think this is the question. Genericity and
  55. > > inheritance both have their uses, and most of the time the design makes
  56. > > clear which of them is appropriate in a given situation. If you think that
  57. > > inheritance is not *really* needed, I can accept that. But my original
  58. > > question was: What do I loose when I have SI only?
  59. >
  60. >     I assume that you left a word out above, since in my post I did
  61. >say that inheritance is sometimes necessary, it is union style
  62. >multiple inheritance that is unnecessary in Ada or any other language
  63. >with sufficiently powerful generic capabilities.
  64. >
  65. Hmm, isn't this exactly what I said? I mean, that MI shouldn't be used to
  66. combine arbitrary classes. Or what do you mean by "union style MI"?
  67.  
  68. > > In what way does the lack of MI affect the usefulness of the whole
  69. > > inheritance idea? *If* I think extensions of a base type should be
  70. > > done using inheritance, how do I solve the problem of combining
  71. > > independent extensions afterwards?
  72. >
  73. >     You don't.  But in general it is always wrong to combine
  74. >extentions which were not intended to be combined.  Ada 9X will give
  75. >you a choice of several combining styles, and in general the language
  76. >will insure that mixtures which are permitted will work.  However,
  77. >since generics mean that the difference between a combining extension
  78. >and normal single inheritance is a few words, you should honor the
  79. >wishes of the type designer and assume that two types which can't be
  80. >mixed shouldn't be mixed:
  81. >
  82. > [ ..example deleted.. ]
  83. >
  84. Yes and no. It is important to make a distinction between combining
  85. arbitrary extensions and extensions which should not be combined. IMHO,
  86. it is illegal to state that *if* I want to combine extensions, these
  87. possible extensions must be known to the base type. It's a quite
  88. natural situation that I want extensions to be mixable, but I cannot
  89. predict how many extensions there will be.
  90.  
  91. Another example: In a tree, I have nodes. Every node is member of a node
  92. class. This class determines which attributes the node carries. Now, the
  93. classes are arranged into a hierarchy. I might want to build abstract
  94. syntax trees using this; with node classes for identifiers, statements
  95. (with appropriate subclasses for special statements) and the like.
  96. Now there are obvious occurences of MI in this example: An applied
  97. occurrence of an identifier in an expression is a subclass of identifier
  98. (i.e. carries the "name-of-identifier" attribute) as well as a subclass
  99. of the expression component, say factor (has e.g. a "value" attribute).
  100.  
  101. I hope this clarifies my point. The writer of the base class for the nodes
  102. doesn't want to know in what way his class will be augmented; i.e. which
  103. node classes there will be and what attributes they have. But still, the
  104. type designer might want these to be combined.
  105.  
  106. >     If it weren't for the fact that generics are IMHO a much more
  107. >powerful tool than inheritance, I could argue that using generics to
  108. >implement mix-ins is like using a sledgehammer to swat flies.  But
  109. >since Ada has all of the necessary support for generics for other
  110. >reasons, it seems silly to talk about adding MI because maybe someday
  111. >someone will think of an application where classical MI is
  112. >significantly better.  (In my opinion, and that of a lot of other
  113. >software engineers, the ability to express "Watch it!" in the code is
  114. >a definite advantage.  In Ada 9X using inheritance in a non-generic
  115. >fashion will be a strong warning message that this new type has more
  116. >than mix-in semantics.)
  117. >
  118.  
  119. Sorry, but I still don't see how you handle polymorphism with generics.
  120. One last example on this: Suppose you have some container class, let's
  121. say a list. In this list, you want to store objects of different types.
  122. In the implementation of the list, you don't know what types, you don't
  123. even know how many. In fact, you *shouldn't* know this, because it has
  124. nothing to do with the list itself. Now, please, how do you do this with
  125. generics?
  126.  
  127. Peter
  128. ---
  129. Peter Klein                        E-Mail: pk@rwthi3.informatik.rwth-aachen.de
  130. Lehrstuhl fuer Informatik III      Tel.: +49/241/80-21320
  131. Ahornstrasse 55                    Fax.: +49/241/80-21329
  132. RWTH Aachen
  133. D-5100 Aachen
  134. Germany
  135.  
  136.