home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / object / 4609 < prev    next >
Encoding:
Text File  |  1992-12-21  |  4.0 KB  |  103 lines

  1. Newsgroups: comp.object
  2. Path: sparky!uunet!usc!cs.utexas.edu!torn!nott!cunews!cunews!knight
  3. From: knight@mrco.carleton.ca (Alan Knight)
  4. Subject: Re: Object hidden state and side effects
  5. Message-ID: <knight.724904387@cunews>
  6. Sender: news@cunews.carleton.ca (News Administrator)
  7. Reply-To: knight@mrco.carleton.ca (Alan Knight)
  8. Organization: Carleton University
  9. References: <BzF6uA.1u3@inews.Intel.COM> <1992Dec17.221333.3023@midway.uchicago.edu> <knight.724800436@cunews> <1992Dec20.162050.14652@midway.uchicago.edu>
  10. Date: Mon, 21 Dec 1992 02:19:47 GMT
  11. Lines: 92
  12.  
  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. >>[Misattributes my stuff to Ben Bongalon, but I'll cope.]
  18.  
  19. Sorry.
  20.  
  21. >>As far as the particular question of objects and values is concerned,
  22. >>there are really two separate issues which I think are orthogonal: the
  23. >>presence of an identity operation separate from equality and
  24. >>mutability. We get four classes of things, which I'm going to call by
  25. >>the names that have been used in this discussion, even if I don't
  26. >>think they're entirely appropriate.
  27. >>
  28.  
  29. >The problem is just what your expecting equality to do.  If it's just
  30. >another comparison, then all of the following make sense.   If you also
  31. >expect equality to satisfy "substituting equals for equals gives equals",
  32. >things get more difficult.  In that case, mutable objects pretty much must
  33. >have equality as identity.
  34.  
  35. I don't believe this. While it is certainly possible for the
  36. programmer to define equality operations that do not satisfy such
  37. constraints, all that means is that one must either trust the
  38. programmer or have a mechanism to enforce the constraints.  I cannot
  39. accept that I am not allowed to use strcmp or even strcasecmp as the
  40. equality operation for my mutable string class. 
  41.  
  42. Furthermore, the axioms you define for equality fall down for a large
  43. class of reasonable values (let alone objects) such as approximations
  44. for floating point numbers (e.g. interval arithmetic). The fact that
  45. they fall down for these type of objects/values/whatever makes
  46. programming with them difficult, but that doesn't mean people don't
  47. want to use them.
  48.  
  49. You seem to be willing to do a lot of work in some areas, but just
  50. dismiss others as too difficult without much thought.
  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. >>Values: Have no operations which modify state, have no identity
  69. >>operation. e.g. numbers
  70. >>
  71. >>Normal storage (or mutable values): State can be modified, but there
  72. >>is no identity operation. e.g. storage allocated on the stack in
  73. >>traditional languages. 
  74.  
  75. >'Splain me, boss.  I'm feeling dumber than usual.
  76.  
  77. Think of a "normal" procedural language, e.g. C.
  78.  
  79. int i;
  80. i=0;
  81. i++;
  82.  
  83. I have just modified the internal state of i. If you don't believe that, try 
  84.  
  85. struct counter {
  86.   int i;
  87. }
  88. counter j;
  89. j.i++
  90.  
  91. (apologies for poor C syntax) I can modify the internal state of a
  92. counter, but there is no meaningful identity operation for
  93. stack-allocated counters.  The best I can do is to take pointers to
  94. them and compare those for identity, but I submit that identity of
  95. references is something different from identity of the things
  96. themselves.
  97.  
  98. -- 
  99.  Alan Knight  knight@mrco.carleton.ca  +1 613 788 2600x1027 
  100.  Dept. of Mechanical and Aerospace Engineering              
  101.  Carleton University, Ottawa, Ontario, Canada, K1S 5B6      
  102.  
  103.