home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #31 / NN_1992_31.iso / spool / comp / object / 4614 < prev    next >
Encoding:
Text File  |  1992-12-21  |  5.4 KB  |  125 lines

  1. Newsgroups: comp.object
  2. Path: sparky!uunet!uchinews!alex!dave
  3. From: dave@alex.uchicago.edu (Dave Griffith)
  4. Subject: Re: Object hidden state and side effects
  5. Message-ID: <1992Dec21.144848.20603@midway.uchicago.edu>
  6. Sender: news@uchinews.uchicago.edu (News System)
  7. Organization: University of Chicago
  8. References: <knight.724800436@cunews> <1992Dec20.162050.14652@midway.uchicago.edu> <knight.724904387@cunews>
  9. Date: Mon, 21 Dec 1992 14:48:48 GMT
  10. Lines: 113
  11.  
  12. In article <knight.724904387@cunews> knight@mrco.carleton.ca (Alan Knight) writes:
  13. >In <1992Dec20.162050.14652@midway.uchicago.edu> dave@alex.uchicago.edu (Dave Griffith) writes:
  14. >
  15. >>In article <knight.724800436@cunews> knight@mrco.carleton.ca (Alan Knight) writes:
  16. >
  17. >
  18. >>The problem is just what your expecting equality to do.  If it's just
  19. >>another comparison, then all of the following make sense.   If you also
  20. >>expect equality to satisfy "substituting equals for equals gives equals",
  21. >>things get more difficult.  In that case, mutable objects pretty much must
  22. >>have equality as identity.
  23. >
  24. >I don't believe this. While it is certainly possible for the
  25. >programmer to define equality operations that do not satisfy such
  26. >constraints, all that means is that one must either trust the
  27. >programmer or have a mechanism to enforce the constraints.  I cannot
  28. >accept that I am not allowed to use strcmp or even strcasecmp as the
  29. >equality operation for my mutable string class. 
  30. >
  31. >Furthermore, the axioms you define for equality fall down for a large
  32. >class of reasonable values (let alone objects) such as approximations
  33. >for floating point numbers (e.g. interval arithmetic). The fact that
  34. >they fall down for these type of objects/values/whatever makes
  35. >programming with them difficult, but that doesn't mean people don't
  36. >want to use them.
  37. >
  38. >You seem to be willing to do a lot of work in some areas, but just
  39. >dismiss others as too difficult without much thought.
  40. >
  41.  
  42. My problem is sadly that I've done too much work in other areas, namely
  43. defining the semantics of interobject relations.  At some low level, relations
  44. have to be worked with as sets of tuples.  Sets is the key word here, as
  45. it's kind of difficult to work reasonably with sets without a strong
  46. equality operation.  Weak set theories without such an equality do exist,
  47. but it becomes almost impossible to specify useful work in them.  Frankly
  48. the payoff from direct support for interobject relations seemed to more
  49. than make up for the sacrafice of restricted equality.  Perhaps your right,
  50. and I've just talked myself into my position. 
  51.  
  52. >>>Mutable objects: Have an identity operation, can be modified.
  53. >>>The default case of objects.
  54. >>>
  55. >>>Immutable objects: Have no operations which modify state, but have an
  56. >>>identity operation. e.g. non-mutable strings
  57. >
  58. >>Might be useful, although the need for an identity operation for non-mutable
  59. >>strings escapes me.
  60. >
  61. >For mutable strings you are willing to make identity the only equality
  62. >operation, but you can't see a reason for using it at all on
  63. >non-mutable strings?  I personally don't use identity operations much
  64. >except as an efficiency hack, but it can be quite valuable there.
  65. >Don't functional languages provide an identity operation? Certainly
  66. >LISP does. Maybe we should ask a functional programmer.
  67. >
  68.  
  69. Certainly the pure functional languages provide no such operation, as it 
  70. would completely trash referential transparency.  ML might get away with it.
  71.  
  72. >>>Values: Have no operations which modify state, have no identity
  73. >>>operation. e.g. numbers
  74. >>>
  75. >>>Normal storage (or mutable values): State can be modified, but there
  76. >>>is no identity operation. e.g. storage allocated on the stack in
  77. >>>traditional languages. 
  78. >
  79. >>'Splain me, boss.  I'm feeling dumber than usual.
  80. >
  81. >Think of a "normal" procedural language, e.g. C.
  82. >
  83. >int i;
  84. >i=0;
  85. >i++;
  86. >
  87. >I have just modified the internal state of i. If you don't believe that, try 
  88. >
  89. >struct counter {
  90. >  int i;
  91. >}
  92. >counter j;
  93. >j.i++
  94. >
  95. >(apologies for poor C syntax) I can modify the internal state of a
  96. >counter, but there is no meaningful identity operation for
  97. >stack-allocated counters.  The best I can do is to take pointers to
  98. >them and compare those for identity, but I submit that identity of
  99. >references is something different from identity of the things
  100. >themselves.
  101. >
  102.  
  103. Hmmm, maybe we haven't been talking about the same thing after all.
  104. In the first case, there is no object or value that is having it's state
  105. altered.  A variable, i, is being successively bound to different values.
  106. Variables are certainly not in any way what I was speaking of when I 
  107. spoke of objects.  In the second case, counters are certainly reasonable 
  108. objects.  I realize that to do identity checking of compound objects in C you 
  109. first must get a reference to them. This seems a minor syntactic bug in
  110. C, much like requiring dynamic function calls to use pointer syntax.  The
  111. semantics of object identity are there, however.
  112.  
  113. On the other hand, you and Ralph Johnson have given me a few quite good 
  114. examples to think about.  I had simply forgotten IEEE float when trying to
  115. come up with good non-reflexive equality example.  Interval arithmetic
  116. struck me as an example of a kind of thing (we're running out of words)  
  117. without a good equality operation.  Here I was having such fun doing 
  118. compiler optimizations and now I have to go back to the language semantics...
  119.  
  120.  
  121. -- 
  122. Dave Griffith, Information Resources, University of Chicago,
  123. Department of Surgery                       dave@alex.bsd.uchicago.edu
  124. A man's best friend is his dogma.
  125.