home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / c / 20048 < prev    next >
Encoding:
Internet Message Format  |  1993-01-21  |  7.4 KB

  1. Xref: sparky comp.lang.c:20048 comp.lang.c++:19725
  2. Path: sparky!uunet!elroy.jpl.nasa.gov!usc!howland.reston.ans.net!zaphod.mps.ohio-state.edu!uwm.edu!cs.utexas.edu!geraldo.cc.utexas.edu!emx.cc.utexas.edu!not-for-mail
  3. From: jamshid@emx.cc.utexas.edu (Jamshid Afshar)
  4. Newsgroups: comp.lang.c,comp.lang.c++
  5. Subject: Re: C/C++ Speed
  6. Date: 21 Jan 1993 21:50:37 -0600
  7. Organization: The University of Texas at Austin, Austin, Texas
  8. Lines: 154
  9. Message-ID: <1jnqudINNfcq@emx.cc.utexas.edu>
  10. References: <1993Jan11.163852.19740@informix.com> <24592@alice.att.com> <mg.726986956@tyrolia>
  11. NNTP-Posting-Host: emx.cc.utexas.edu
  12.  
  13. In article <mg.726986956@tyrolia> mg@tyrolia (Michael Golan) writes:
  14. >2. Stroustrup claims:
  15. >>    Programs in the common subset of C and C++ results in
  16. >>    equal sized code that execute at equal speed.
  17. >>If that conclusion doesn't appear to hold, check if your C and C++
  18. >>compilers are of similar quality. 
  19. >
  20. >This is the #1 problem of C++, poor implementation!
  21. >We have been waiting for years, literally. But by the time the vendors get
  22. >a version stable, the language has changed enough to force a compiler
  23. >rewrite. 
  24.  
  25. Stroustrup is talking about identical code compilable by both a C and
  26. a C++ compiler.  I've haven't experienced a slowdown when compiling my
  27. C code with a C++ compiler (though I have found errors in the code).
  28. Yes, C++ compilers, esp.  earlier versions, have had lots of bugs
  29. related to C++ features (esp. newly implemented ones).  But, I know of
  30. no C++ compilers that have problems compiling C code well.
  31.  
  32. Yes, templates and exception handling require a lot of work from
  33. compiler writers.  Yes, the early implementations of these features
  34. do/will have bugs.  As I have said before, I am still much more
  35. productive using templates and working around bugs than not using
  36. templates.  If you don't want to work around compiler bugs, don't use
  37. templates.  I believe you can rather safely and portably write C++
  38. w/out templates on all modern C++ compilers.
  39.  
  40. >Lets compare apples to apples. On most systems, today, the C++ 
  41. >implementation is incomplete, buggy and overall poor. Still, people 
  42. >are moving to use it, which doesn't show sanity on their side.
  43.  
  44. On the PC, the most widely used system, the two most popular compilers
  45. are MSC7 and BC++.  I would not describe either of them as poor or
  46. buggy.  I don't know about UNIX, Mac, etc., but I can't think of any
  47. reason for PC programmers to shy away from C++ since their C compilers
  48. also do C++, and do it well.
  49.  
  50. >3. Size/speed:
  51. >If you have a virtual function in a class, it gets pulled in even if
  52. >it is never called. No linkers exist to prevent this, as far as I know.
  53.  
  54. I've heard Topspeed C++ does this kind of optimization.  Anyway, I
  55. don't think it's that serious of a problem.  Even non-optimizing
  56. linkers will usually only pull in an object file from a library if
  57. something in there is referenced (ie, if no ctor in the file is used,
  58. no vtable is referenced).
  59.  
  60. >Given that ALL C++ libraries use virtual functions, the size difference is
  61. >significant.
  62.  
  63. Well, the general C++ class library JCOOL (see pub/GECOOL/JCOOL.TXT at
  64. cs.utexas.edu) uses virtual functions in only one of its classes:
  65. List.  The other couple of dozen classes (sets, hash tables, matrices,
  66. etc) don't use virtual functions.  C++ doesn't force one to use
  67. virtual functions, and I think you can write a lot of useful classes
  68. without them.
  69.  
  70. >Most C++ code has comments about buggy compilers, amazing as this may sound.
  71.  
  72. I don't think this is amazing at all.  Buggy software is a fact of
  73. life, whether that software is a compiler, os or application.
  74.  
  75. >4. Safety
  76. >   C++ does not protect againt typical system code:
  77. >    write_int(int x) {
  78. >    char *p ;
  79. >    p = (char *) x;    // oops, I meant &x !!
  80. >    write(f,p,sizeof(int));
  81. >    }
  82.  
  83. This is silly.  C++ (and ANSI C) do protect you from these kind of
  84. errors because they allow you to use safer functions which don't
  85. require a cast.  C++ goes further in that its data abstraction,
  86. template, and inheritance features allow you to better implement
  87. persistence.
  88.  
  89. >   it "adds" stuff like        double (x) ;   // declare new x ?! 
  90. >   and don't complain about    
  91. >    double **x;
  92. >    x= (new double**)[5] ;    /* the compiler liked it! */
  93.  
  94. Yes it would be nice if the compiler complained, but the code is
  95. syntacticly legal.  What's your point?  C is where C++ got the ability
  96. to write obfuscated stuff like this.  The advantage of C++ is that it
  97. allows you to do the following instead:
  98.  
  99.     Matrix<double> x(5,5);
  100.     Array<double> z(5);
  101.     x[5] = z;
  102.  
  103. >I am amazed at the number of people who are moving to C++ when it is
  104. >clear, even if this is the prefect langauge, that the 
  105. >implementation and quality are at least a year away.
  106.  
  107. No software's quality improves unless people are using it.  With the
  108. number of people using C++, and the amount of code being written, C++
  109. compiler quality will increase (and has been increasing) at a much
  110. higher rate.
  111.  
  112. You can already safely and portably use most of C++'s features.  I
  113. predict practically all template implementations will be very stable
  114. by the end of this year and that template implementations will be
  115. wide-spread.  On the other hand, I doubt we'll even *see* more
  116. than a couple of exception handling implementations this year.
  117.  
  118. >All of these, when they
  119. >had all the tools and knowledge to design a good language which will
  120. >have most C's features and speed, but with higher abstraction, better
  121. >modularity, run time checks, etc etc.
  122.  
  123. First, I hope you agree that no language could replace C unless it
  124. also could work with C code, at least by linking to it but more likely
  125. actually compiling it.  If there is a better language that can replace
  126. C, where is it and where can I get a copy for my DOS/Windows system?
  127.  
  128. >They will also wonder about our ability to do anything, when no decent
  129. >tools exist, not even for cross-referencing!
  130.  
  131. C++ tools in general are not near the maturity level of C tools.
  132. There are some systems that have C++ tools as good or better than the
  133. C tools, but most systems are not at that level.  This is the way it
  134. is with any new technology.  Programmers have to decide when they are
  135. ready for a new technology, and when it is ready for them.
  136.  
  137. >For C++ it is clearly too late. C++ is a committee work. Which means
  138. >all the stupid features will be kept, no useful stuff will be added, 
  139. >and wierd useless stuff will be added. 
  140.  
  141. I think exception handling is a pretty useful feature.  What stupid
  142. features can be removed with breaking C compatibility?  What weird
  143. useless stuff is being added?
  144.  
  145. >New discussion: if there was a new language, D, that had the same low
  146. >level C code, much cleaner design, and C style ( {} and not begin-end, etc,
  147. >most C code easily ported, if not compatible), would you use it? 
  148. >What will it take for people to consider an alternative to C++? 
  149. >Lets say it is a watered-down C++, fewer rules, no MI, real type checks
  150. >including pointers and runtime etc. do you buy it?
  151.  
  152. Btw, MI is very important in a staticly typed language (go argue in
  153. comp.lang.eiffel if you don't agree).
  154.  
  155. How can your hypothetical D language both compile the same low level C
  156. code, and do run-time type checking, etc?  If Stroustrup didn't care
  157. about C compatibility, he could have designed a much better and safer
  158. language.  Unfortunately it would never have gotten used.
  159.  
  160. You cannot replace something without providing a way to easily use the
  161. thing being replaced.  That is now taken for granted in operating
  162. systems, why is it so hard for people to accept that the same goes for
  163. computer languages?
  164.  
  165. Jamshid Afshar
  166. jamshid@emx.utexas.edu
  167.