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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!pmafire!news.dell.com!swrinde!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
  3. From: mccall@mksol.dseg.ti.com (fred j mccall 575-3539)
  4. Subject: Re: FORTRAN bug(was Re: C++ vs. Ada -- Is Ada loosing?)
  5. Message-ID: <1992Dec14.165537.18275@mksol.dseg.ti.com>
  6. Organization: Texas Instruments Inc
  7. References: <EACHUS.92Dec7184734@oddjob.mitre.org> <1992Dec8.072300.21473@smds.com> <1992Dec8.172551.16780@newshost.lanl.gov> <1992Dec9.060218.23940@seas.gwu.edu> <1992Dec11.132942.24054@mksol.dseg.ti.com> <1992Dec11.163811@lglsun.epfl.ch>
  8. Date: Mon, 14 Dec 1992 16:55:37 GMT
  9. Lines: 164
  10.  
  11. In <1992Dec11.163811@lglsun.epfl.ch> nebbe@lglsun.epfl.ch (Robb Nebbe) writes:
  12.  
  13. >Michael Feldman:
  14.  
  15. >   int x;
  16. >   ...
  17. >   x = 1;
  18. >   while (x <= 10);
  19. >   { 
  20. >      printf("%d\n", x);
  21. >      x++;
  22. >   }
  23.  
  24. >For 10 points on your grade: what is printed? Why?
  25. >Try explaining it to a freshman.
  26.  
  27.  
  28. >Fred McCall:
  29. >Nothing is printed.  You built an infinite loop.  This is hard to
  30. >understand?  You made a while loop with an empty body and a condition
  31. >that is never met because you never increment x.  Your freshmen don't
  32. >get this?
  33.  
  34. >Me:
  35.  
  36. >Good syntax means that code should do what it looks like it should do. The
  37. >above code is an example of less than optimal bordering on poor language
  38. >syntax. 
  39.  
  40. It looks like it does what it should do to me, other than the abysmal
  41. and unnecessary use of braces and indentation.  It's the language's
  42. fault that poor coders can write poorly formatted code?
  43.  
  44. >The reason being that many compilers don't detect that what is
  45. >obviously wrong code is wrong. On top of that the problem is rather inocuous
  46. >and if I didn't know that the problem was there I might miss it when reading
  47. >through the code. Basically the presence of a typo must be detected by having
  48. >your program hang. A far from optimal situation.
  49.  
  50. Well, I prefer to think of it as the presence of a typo must be
  51. detected by knowing the language -- a situation that is hardly
  52. peculiar to C, and that is, in fact, pretty much a prerequisite for
  53. writing working code in ANY language.
  54.  
  55. >The far worse problem with C syntax is the one that caused the problem for
  56. >ATT. (This is all second hand so anyone in the know should correct me if I'm
  57. >wrong.) A programmer had left out a break in a switch statement. I don't
  58. >know the what the actual code was like by a switch looks like this.
  59.  
  60. From reports I've seen, this isn't what caused the problem.
  61.  
  62. >   switch (x)
  63. >   {
  64. >      case 1:
  65. >         printf("x == 1\n");
  66. >         break;
  67. >      case 2:
  68. >         printf("x == 2\n");
  69. >         break;
  70. >      default:
  71. >         printf("x != 1 && x != 2\n");
  72. >   } 
  73. >   printf("done");
  74.  
  75. >The break is necessary to leave the switch because the cases only serve as
  76. >labels and execution will fall through to the next case statement. This is a
  77. >case (no pun) where assembler shows through the C syntax. The machine code that
  78. >is generated for the switch is a jump table based on the value of x. At the end
  79. >of the statements another jump is required to avoid executing the rest of the
  80. >code from the other case statements. 
  81.  
  82. Gee, once again one is expected to know the language to write working
  83. code in the language.  Funny how that works.  And if I implement the
  84. wrong algorithm in Ada, it will tell me that I've made an error?
  85.  
  86. Just by the way, I believe that the actual problem was caused by
  87. someone who put a 'break' statement inside an 'if', with the intention
  88. of exiting the 'if' from the middle.  Of course, this doesn't work,
  89. and he actually wound up leaving an enclosing loop prematurely.  It
  90. was something like that, anyway.  The problem was the PRESENCE of a
  91. 'break', not the absence of one.
  92.  
  93. >The fact that these problems exist in C is well known and most C texts point
  94. >them out. I would like to point out that these idiosyncracies have not
  95. >prevented C from being succesfully used in a phenomenal amount of code.
  96.  
  97. >People need to put C in perspective. When people started using C it was 
  98. >because the choice was between assembler and C for many projects. For larger
  99. >projects the choice was between something like FORTRAN with some assembler
  100. >and C. My experience in mixing assembler and FORTRAN is very limited but it is
  101. >far from a trivial endevour. In both cases I would unhesitatingly choose C.
  102.  
  103. >Now there are other choices such as Ada for doing programs that interface with
  104. >the hardware. Why do people keep using C? A lot of it has to do with inertia.
  105. >Another reason that we shouldn't forget is that a good C/C++ programmer can
  106. >turn out some very high quality code and if it aint broke don't fix it. In 
  107. >fact I would go as far as to say that well written C/C++ code is almost as
  108. >readable as Ada.
  109.  
  110. Personally, I find well-written C a lot MORE readable than Ada.  But I
  111. think the point is well taken.  It is possible to write opaque code in
  112. ANY language.
  113.  
  114. >The problem with Ada is that it is a lot more difficult to do code generation
  115. >in my head ;-) Some of you will scoff but my education is in computer
  116. >engineering (thus hardware) and there is a tremendous amount a satisfaction in
  117. >knowing what it is that I am telling the hardware to do and not just in the
  118. >abstract sense.
  119.  
  120. >When I program in Ada this sense of satisfaction is just not there. Programming
  121. >in C is sort of like making a piece of furniture yourself from scratch and
  122. >programming in Ada is like buying a kit. 
  123.  
  124. >However I put such personal feelings aside when I have to do a project because
  125. >my level of confidence in 5000 lines of Ada is definitely higher than my
  126. >level of confidence in 5000 lines of C/C++. This isn't that I'm a better
  127. >programmer in Ada than in C/C++. To the contrary I'm sure that I master C
  128. >better than Ada but I probably know Ada better than C++. The reason is that
  129. >when I write code in Ada it usually won't compile if it wasn't what I meant.
  130. >In C/C++ the compiler isn't as helpful. For novice Ada programmers however this
  131. >is viewed as frusterating because the compiler won't except their code and it
  132. >is what they mean :^)
  133.  
  134. >Michael Feldman:
  135. >|> >Any similar idiosyncracies in Ada? 
  136.  
  137. >Fred McCall:
  138. >|> 
  139. >|> Single character ones?  Probably not, but that just indicates that Ada
  140. >|> is incredibly more verbose than C.  One of the things I DISlike about
  141. >|> it, by the way.
  142.  
  143. >Me:
  144.  
  145. >Actually the fact that Ada is verbose has absolutly nothing to do with the
  146. >fact that it doesn't have any similar idiosyncracies. The difference is that
  147. >the syntax of Ada was studied to avoid such problems and this wasn't a 
  148. >concern when they thought up the syntax for C. If they designers of C had been
  149. >interested in avoiding such problems it wouldn't have been too hard.
  150.  
  151. Well, there is just a bit more to it that that, and I think someone
  152. back there a while ago posted a list showing a few 'peculiar'
  153. structures for Ada, as well.  I wish I still had it.
  154.  
  155. >Robb Nebbe                nebbe@lglsun.epfl.ch
  156.  
  157. >P.S. If you don't put the breaks in the switch it would print the following
  158. >if x == 1:
  159.  
  160. >x == 1
  161. >x == 2
  162. >x != 1 && x != 2
  163. >done
  164.  
  165. This is a surprise?  If you don't put in the print statements it
  166. doesn't print anything.  These two results are about equally
  167. surprising. 
  168.  
  169. -- 
  170. "Insisting on perfect safety is for people who don't have the balls to live
  171.  in the real world."   -- Mary Shafer, NASA Ames Dryden
  172. ------------------------------------------------------------------------------
  173. Fred.McCall@dseg.ti.com - I don't speak for others and they don't speak for me.
  174.