home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / lang / cplus / 16512 < prev    next >
Encoding:
Internet Message Format  |  1992-11-18  |  3.8 KB

  1. Path: sparky!uunet!ogicse!emory!sol.ctr.columbia.edu!ira.uka.de!slsvaat!josef!kanze
  2. From: kanze@us-es.sel.de (James Kanze)
  3. Newsgroups: comp.lang.c++
  4. Subject: Re: Should I use a generic object which all others inherit from
  5. Message-ID: <KANZE.92Nov18163531@slsvdnt.us-es.sel.de>
  6. Date: 19 Nov 92 00:35:31 GMT
  7. Article-I.D.: slsvdnt.KANZE.92Nov18163531
  8. References: <3762@news.cerf.net> <1992Nov17.190821.18348@informix.com>
  9. Sender: news@us-es.sel.de
  10. Organization: SEL
  11. Lines: 83
  12. In-Reply-To: cshaver@informix.com's message of 17 Nov 92 19:08:21 GMT
  13.  
  14. In article <1992Nov17.190821.18348@informix.com> cshaver@informix.com
  15. (Craig Shaver) writes:
  16.  
  17.  
  18. |> In article <3762@news.cerf.net> hlf@nic.cerf.net (Howard Ferguson) writes:
  19. |> >I am working on the early stages of design on an embedded C++
  20. |> >project. One of the decisions which we will have to make in the
  21. |> >near future is whether to make all of the objects inherit from 
  22. |> >onie generic object at the top of the tree or to go for the forest 
  23. |> >approach. 
  24. |> >
  25. |> .................
  26. |> >
  27. |> >
  28. |> >        Many thanks,
  29. |> >            hlf
  30.  
  31. |> An embedded system!  C++!?  JUST USE C!!!!
  32.  
  33. |> UNLESS ....
  34.  
  35. |> You have some of the benefits of OOP in mind, such as inheritance, reuse, 
  36. |> and information hiding.
  37.  
  38. UNLESS...
  39.  
  40. You want the added security of additional static type checking,
  41. encapsulation, etc.
  42.  
  43. I have found that the encapsulation you get from C++ (by writing a
  44. class instead of a struct and some functions) is an even bigger win
  45. than any of the object oriented stuff.
  46.  
  47. On the project I'm currently working on, we recently had to completely
  48. change the representation and implementation of one class, replacing a
  49. simple, intuitive implementation by one that was more complex, but a
  50. magnitude more efficient.  Incidence on users of the class: 0.  On
  51. every project I've been on, this has been an acknowledge goal.  With
  52. C, however, we were never able to succeed completely.  Here, the class
  53. author didn't even think about it this, but it worked automatically.
  54.  
  55. |> Then if you are willing to take small dings in
  56. |> performance go all the way and use the tree approach as pioneered by
  57. |> Smalltalk.  I recently saw a review of the toy code that comes with the
  58. |> borland compiler.  The article's author commented that the tree type
  59. |> libraries were "passe" because of templates.  What a stupid thing to say!
  60.  
  61. The Smalltalk approach is fine for prototyping, but I certainly
  62. wouldn't use it in an embedded system.  Basically, it trades off
  63. compile time checks for run-time checks.
  64.  
  65. If the compiler says error, you correct the code and recompile.  What
  66. do you do if you get a type error at run-time?
  67.  
  68. |> One of the big wins of OOP is reuse.  By using an inheritance structure
  69. |> you can reuse existing code and do incremental development.  Related and
  70. |> unrelated classes can be used in the same context where a similar protocol
  71. |> is enforced.  
  72.  
  73. Agreed.
  74.  
  75. |> I have to think some of the people involved with C++ have no idea what the
  76. |> basis of OOP really is.  They are simply using C++ as an improved C.
  77.  
  78. Or as an alternative to Ada.  Or because they want some of the
  79. features of Ada, some of Pascal, and some of C.
  80.  
  81. C++ is not without problems.  The language is big and complex (and
  82. growing daily).  It is difficult for beginners (and sometimes for
  83. experienced people) to understand the interreactions between the
  84. different features.  The closest thing we have to a standard, the ARM,
  85. is full of ambiguities and undefined areas.
  86.  
  87. But if you just take your C design, convert the struct's to classes,
  88. and make all functions that operate on the struct members, and you've
  89. already got a big win.  Then, as you begin to add inheritance and
  90. classes that are used for their behavior rather than simply to hold
  91. state, you'll find that it gets even better.
  92. --
  93. James Kanze            GABI Software, Sarl.
  94. email: kanze@us-es.sel.de    8 rue du Faisan
  95.                 67000 Strasbourg
  96.                 France
  97.