home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / object / 4640 < prev    next >
Encoding:
Internet Message Format  |  1992-12-22  |  5.2 KB

  1. Path: sparky!uunet!gatech!darwin.sura.net!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!sun-barr!sh.wide!wnoc-tyo-news!etl.go.jp!ume!crimson!kekux!s.u-tokyo!is.s.u-tokyo!jeff
  2. From: jeff@is.s.u-tokyo.ac.jp (Jeff McAffer)
  3. Newsgroups: comp.object
  4. Subject: Re: Equality
  5. Message-ID: <1992Dec22.152021.4209@kei.is.s.u-tokyo.ac.jp>
  6. Date: 22 Dec 92 15:20:18 GMT
  7. References: <1992Dec21.184405.2215@midway.uchicago.edu>
  8. Sender: news@kei.is.s.u-tokyo.ac.jp (Usenet News System)
  9. Reply-To: jeff@is.s.u-tokyo.ac.jp
  10. Organization: University of Tokyo / Object Technology International
  11. Lines: 108
  12.  
  13. In article <1992Dec21.184405.2215@midway.uchicago.edu> dave@alex.uchicago.edu (Dave Griffith) writes:
  14.  
  15.  >So just what exactly do you all mean when you say "equality"?
  16.  
  17. For me, equality means that two equal objects can be pretty much
  18. interchanged.  They are "essentially the same".  This means that they
  19. should have the same protocol/bahaviour but need not be of the same
  20. class or have a common superclass.
  21.  
  22.  >1) Equality should be reflexive.  
  23.  >      I thought this was obvious, but IEEE754 may provide a counterexample.
  24.  >
  25.  >2) Equality should be symettric.
  26.  >3) Equality should be transitive.
  27.  >4) Substitution of equals for equals should give equals.
  28.  >5) If two objects are equal at one point in program execution, they should be
  29.  >     equal at all points. 
  30.  >6) Assignment should respect equality.   (Assuming no side-effects, after 
  31.  >   executing x:=a; it should be true that x=a.
  32.  >7) If your parameter passing model is based on assignment, 6) should hold 
  33.  >   mutatis mutandi.
  34.  >8) If two objects are equal, they should be behaviourally indistinguishable. 
  35.  >   The converse need not hold, but often will.
  36.  >9) Two sets A,B are equal iff  for_all(x:A)there_exists(y:B) such y=x, and
  37.  >   vice versa.
  38.  
  39. I agree with all but #5.  #9 I take the generic set meaning where the
  40. containment function is = (equals).  There are other useful
  41. containment functions which my result in #9 failing.
  42.  
  43.  >Given mutable objects, identity was the only practical definition I found
  44.  >which would  support all of the above.  However, identity is not a practical 
  45.  >equality definition for all objects we wish to program with (vis, integers). 
  46.  >In these cases, if immutability holds, users may be able to define equality
  47.  >in ways which satisfy the above, and there are good reasons to let them try. 
  48.  
  49. Agreed.  Given the above, equals => identity (mutable case) or =>
  50. immutability.
  51.  
  52. However, you asked how "we" thought of equals.  For me (prior to these
  53. discussions), identity was the default idea of equals.  Certainly the
  54. most applicable and safest.  It was only in cases where I could have
  55. multiple objects which could behave similarly (read equally) that I
  56. would define a different equals operation. It means that these two are
  57. interchangeable BUT point #5 above does not necessarily hold because I
  58. know that the objects may be different physical bits of memory and
  59. thus may be changed independently.  As for immutable objects, well
  60. typically immutability and uniqueness go hand in hand so the equals is
  61. identity definition works just fine.
  62.  
  63. This is entirely from a programming point of view.
  64.  
  65. It does seem to be #5 that is the sticking point.  You use that point
  66. to say that only identity is reasonable for "objects" and to get away
  67. with saying that you can use = for "values".  Ok but that is different
  68. from my ideas from programming and likely the source of much of the
  69. confusion (at least mine).
  70.  
  71. Just a thought.  If you accept your definition of equality then you
  72. could implement an equal op that whenever it returned true would
  73. delete the argument from the system and replace it with the receiver!
  74. Cool!
  75.  
  76.  >May two objects of different classes be equal?
  77.  
  78. Yes
  79.  
  80.  >May two objects be equal even if they don't respond to the same protocol?
  81.  
  82. No but... I have been known to in the past, define equals based on a
  83. subset of protocol.  That is , two object can be equal if they respond
  84. to this subset and have the other equality properties I want.  Now I
  85. would not claim that this is good or desireable.  It just was.
  86.  
  87.  >If they respond to the same protocol but have no common superclass
  88.  >which defines that protocol (i.e. protocol similarity is incidental)?
  89.  
  90. NO!  In general I do not find many places that I want to separate just
  91. plain ole protocol (i.e., method name, arg count...) from the
  92. semantics of the method.  Esssentially protocol for me includes a
  93. detailed implementation independent description of what the method
  94. does.  Hard to test at run time I know but darn useful when you are
  95. programming.
  96.  
  97.  >If programmers view equality as just another binary predicate, perhaps I 
  98.  >should come up with a different name for the operation I need.  Any 
  99.  >suggestions?
  100.  
  101. Perhaps!  how about "essentiallyTheSame:" :-) 
  102.  
  103. An alternate question is:  What do you call what I call "equality"?
  104.  
  105. The problem with "equals" is that in everyday life we use it for all
  106. sorts of things that are not values and that don't come close to the
  107. properties you outlined.  People for instance.  We say things like men
  108. and women are equal but even if you could find two for which the
  109. principles held, #5 would fail pretty quick.  Alas, people are just
  110. objects.
  111.  
  112. Sorry I let some of the other thread leak in here but it was hard to
  113. avoid.
  114.  
  115.  
  116.  
  117. --
  118. --
  119. ato de, |m        -- Santa or Satan?  Think about it.
  120.