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

  1. Newsgroups: comp.object
  2. Path: sparky!uunet!newsflash.concordia.ca!grogono
  3. From: grogono@cs.concordia.ca (Peter Grogono)
  4. Subject: Re: Object hidden state and side effects
  5. Message-ID: <Bz5ruB.5Mw@newsflash.concordia.ca>
  6. Sender: usenet@newsflash.concordia.ca (USENET News System)
  7. Nntp-Posting-Host: concour.cs.concordia.ca
  8. Organization: Computer Science, Concordia University, Montreal, Quebec
  9. References: <1992Dec9.114035.26542@ruby.comlab.ox.ac.uk> <knight.724021213@cunews> <1992Dec11.163449.18439@crd.ge.com>
  10. Date: Sat, 12 Dec 1992 18:10:59 GMT
  11. Lines: 62
  12.  
  13. In article <1992Dec11.163449.18439@crd.ge.com> eaker@ukulele.crd.ge.com (Chuck Eaker) writes:
  14. >In article <knight.724021213@cunews>, knight@mrco.carleton.ca (Alan Knight) writes:
  15. >
  16. >|> In Smalltalk one cannot delete an object of any kind. One can,
  17. >|> however, create numbers perfectly well. 
  18. >|>   Fraction numerator: 3 denominator: 4 
  19. >|> 
  20. >|> is perfectly valid Smalltalk code which creates a new fraction with
  21. >|> value 3/4. Why is that crazy?
  22. >
  23. >It's crazy because it is not an example of creating a value. The
  24. >value 3/4 has been around a long time. What this example creates
  25. >is yet another digital representation of that value.
  26. >
  27. >It is more accurate to say that you have created space, and in
  28. >that space will be placed a bit pattern which represents a value. 
  29. >But even that is a fiction. What is really created is not space
  30. >but a way to refer to a space which can hold only one of many
  31. >things each of which is taken to represent a value or even a range
  32. >of values.
  33. >
  34. >In short, software must use objects to represent values. This is
  35. >why the distinction between values and objects is of enormous
  36. >importance. . . . . [stuff deleted]
  37. >Chuck Eaker / P.O. Box 8, K-1 3C12 / Schenectady, NY 12301 USA
  38. >eaker@crd.ge.com        eaker@crdgw1.UUCP       (518) 387-5964
  39.  
  40. I completely agree with Chuck's analysis, but I would like to
  41. add my 2 bits' worth.
  42.  
  43. In thinking about, designing, and teaching OOLs, I have found it more
  44. useful to distinguish "mutable objects" and "immutable objects"
  45. rather than "objects" and "values". A class is immutable if all its
  46. objects are immutable.
  47.  
  48. Integers, for example, are immutable. The interpretation of 2+3
  49. is (!): "send message +3 to object 2, giving a new object 5."
  50. If we allowed the object 3 to change into 5, there would be terrible
  51. confusion -- as in FORTRAN.
  52.  
  53. It is better to regard literal constants, such as 57 and "wow",
  54. as constructors with special syntax.
  55.  
  56. For the implementation, immutability allows optimization. It is
  57. not necessary, for example, to create three new objects in order to
  58. evaluate 57+57 (the three objects being "57", "57", and "104").
  59. The reason that it is not necessary is that integers are immutable:
  60. a programmer has no way of discovering that the two objects with
  61. value "57" happen to share space or that the space is never even
  62. allocated (except perhaps in a register).
  63.  
  64. Most languages treat integers, strings, and a few other basic classes
  65. as special, largely because they are efficiently implemented by
  66. hardware. (Peano arithmetic is not good for number crunching.)
  67. The (im)mutable distinction, however, is orthogonal to implementation.
  68. There is no reason why we should not, for example, declare matrices
  69. to be immutable, if we could gain efficiency by so doing.
  70.  
  71. Peter
  72.  
  73.  
  74.  
  75.