home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #30 / NN_1992_30.iso / spool / comp / lang / cplus / 17940 < prev    next >
Encoding:
Text File  |  1992-12-14  |  3.9 KB  |  69 lines

  1. Newsgroups: comp.lang.c++
  2. Path: sparky!uunet!stanford.edu!leland.Stanford.EDU!leland.Stanford.EDU!kocks
  3. From: kocks@leland.Stanford.EDU (Peter Kocks)
  4. Subject: Re: Need help implementic data structures of generic objects
  5. Message-ID: <1992Dec14.212143.15591@leland.Stanford.EDU>
  6. Sender: news@leland.Stanford.EDU (Mr News)
  7. Organization: DSG, Stanford University, CA 94305, USA
  8. References: <1992Dec8.165230.2587@ucc.su.OZ.AU> <42186@sdcc12.ucsd.edu> <1992Dec11.233253.27540@informix.com> <1992Dec13.141400.5307@mole-end.matawan.nj.us>
  9. Date: Mon, 14 Dec 92 21:21:43 GMT
  10. Lines: 57
  11.  
  12. In article <1992Dec13.141400.5307@mole-end.matawan.nj.us>, mat@mole-end.matawan.nj.us writes:
  13. |> In article <1992Dec11.233253.27540@informix.com>, cshaver@informix.com (Craig Shaver) writes:
  14. |>  
  15. |> > YES! Do that elegant Smalltalk thing.  Do not listen to C++ hacks and
  16. |> > bigots.  Put a little thought into it and do something (re)useful.
  17. |> 
  18. |> If you are programming in Smalltalk then by all means use the same
  19. |> language construct for inheritance as for genericity.  But if you
  20. |> are programming in C++, use the right tool: a template.
  21. |> 
  22. |> 
  23. |> When in Smalltalk, Talk Small.  When in C++, think clearly and write
  24. |> clearly.  True elegance means using a thing well as designed.
  25. |> 
  26.  
  27. My $0.02.  Use Obj-C.  I have just spent a fair amount of time comparing strong
  28. vs weak type casting systems (sometimes called static vs. dynamic binding) and
  29. have reached the following conclusions.  C++ is the optimum strong casting
  30. language, Smalltalk is the most popular weak casting system.  The ADVANTAGE
  31. of C++ is that it is strong casting (which makes the prevention of bugs
  32. considerably easier).  The ADVANTAGE of Smalltalk is that it is weak casting.
  33. The disadvantage of C++ is that when you want to do the more complex OOP
  34. techniques, they often make the most sense in a weak casting language.  C++ lets
  35. you get around the need for weak casting by giving you such things as
  36. templates.   Its not exactly the same, but it should enable you to implement
  37. your design.  It also means that C++ gets much more complex as you increase the
  38. complexity of your OOP design.  The disadvantage of Smalltalk is that it can
  39. be slow.  Weak casting systems require somekind of run-time system and hence
  40. smalltalk can be slow.  There are, however, several Smalltalk implementations
  41. which allow a lot of the code to be compiled and it really isn't THAT slow.
  42. The other disadvantage is that smalltalk is not C.  So, all those neat
  43. C tricks you learned are useless.  
  44.  
  45. Weak casting is a nice feature allowing you to send messages to objects without
  46. knowing how (or if) the message can be implemented by the object.  It really
  47. is great, but it makes for run-time errors which are bad (BUT not THAT bad). 
  48. The solution, if you want a weakcasting system and you don't want to give
  49. up C, is clearly Obj-C.  Obj-C is essentially a mix of smalltalk and C.  It
  50. gives you the advantages of weak casting and C code.  While it is not as
  51. fast as C++, the difference is relatively minimal and it is certainly faster
  52. than implementing your own weak casting system in C++.  Of course, no one 
  53. except NeXT really uses Obj-C and this is the biggest problem -- too bad.
  54. Obj-C is avaialable on most platforms.  Obj-C is not as straight forward
  55. to learn as C++ (for people who already known C).  C++ is much closer
  56. to C than Smalltalk.  Obj-C is much closer to Smalltalk.  I think the reason
  57. C++ became so popular is that it is relatively easy to learn OOP from
  58. a C background using C++.  Unfortunately, we are stuck with C++ so the 
  59. ultimate answer I believe is to forget about doing any kind of weak casting
  60. design.  To do it in C++ is inviting disaster.  Smalltalk is not fast 
  61. enough (well maybe it is) and it does not give you C code possiblities.  Obj-C
  62. is the clear answer, but you'll be all alone.  
  63.  
  64. I'm stuck with the same problem and I've decided to curse C++ and just
  65. get on with using templates etc...
  66.  
  67. --Peter Kocks
  68.   kocks@cardinal.stanford.edu
  69.