home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17838 < prev    next >
Encoding:
Internet Message Format  |  1992-12-11  |  2.3 KB

  1. Path: sparky!uunet!wupost!spool.mu.edu!agate!agate!matt
  2. From: matt@physics.berkeley.edu (Matt Austern)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Need help implementic data structures of generic objects
  5. Date: 11 Dec 92 16:26:29
  6. Organization: Lawrence Berkeley Laboratory (Theoretical Physics Group)
  7. Lines: 34
  8. Message-ID: <MATT.92Dec11162629@physics.berkeley.edu>
  9. References: <1992Dec8.165230.2587@ucc.su.OZ.AU> <42186@sdcc12.ucsd.edu>
  10.     <1992Dec10.114636.16861@ucc.su.OZ.AU>
  11.     <1992Dec11.233253.27540@informix.com>
  12. Reply-To: matt@physics.berkeley.edu
  13. NNTP-Posting-Host: physics.berkeley.edu
  14. In-reply-to: cshaver@informix.com's message of 11 Dec 92 23:32:53 GMT
  15.  
  16. In article <1992Dec11.233253.27540@informix.com> cshaver@informix.com (Craig Shaver) writes:
  17.  
  18. > >>class Object {
  19. > >>    /* ...etc... */
  20. > >>};
  21. > >
  22. > >    Dont do this Smalltalk hack please. A queue of Objects is
  23. > >totally useless, since they are just Objects and not ever Widgets.
  24. > YES! Do that elegant Smalltalk thing.  Do not listen to C++ hacks and
  25. > bigots.  Put a little thought into it and do something (re)useful.
  26.  
  27. The problem is that in C++, as opposed to Smalltalk, this *isn't*
  28. terribly elegant.  The question is: what can you do with an Object?
  29. If you put a Widget into a list of Objects, you can't call any of the
  30. Widget member functions; you can only call the Object member
  31. functions.
  32.  
  33. You can, of course, access the Widget member functions by downcasting
  34. the Object* to a Widget*, but I would scarcely call that elegant.
  35. (Also, of course, you're deliberately violating the language's type
  36. checking, so you're opening yourself up to all sorts of fun bugs.)  I
  37. would suggest that if your program makes heavy use of downcasting,
  38. then you are probably not using the best possible design.
  39.  
  40. There probably are some programs for which Smalltalk is a better
  41. choice of language than C++.  For those programs, the simple solution
  42. is just to use Smalltalk; as Dr. Stroustrup has pointed out, Smalltalk
  43. does a far better job of being Smalltalk than C++ ever will.
  44. --
  45. Matthew Austern                   Just keep yelling until you attract a
  46. (510) 644-2618                    crowd, then a constituency, a movement, a
  47. austern@lbl.bitnet                faction, an army!  If you don't have any
  48. matt@physics.berkeley.edu         solutions, become a part of the problem!
  49.