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

  1. Newsgroups: comp.lang.ada
  2. Path: sparky!uunet!cis.ohio-state.edu!zaphod.mps.ohio-state.edu!sdd.hp.com!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!hellgate.utah.edu!lanl!cochiti.lanl.gov!jlg
  3. From: jlg@cochiti.lanl.gov (J. Giles)
  4. Subject: Re: FORTRAN bug(was Re: C++ vs. Ada -- Is Ada loosing?)
  5. Message-ID: <1992Dec14.183326.27689@newshost.lanl.gov>
  6. Sender: news@newshost.lanl.gov
  7. Organization: Los Alamos National Laboratory
  8. 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>
  9. Date: Mon, 14 Dec 1992 18:33:26 GMT
  10. Lines: 50
  11.  
  12. In article <1992Dec11.163811@lglsun.epfl.ch>, nebbe@lglsun.epfl.ch (Robb Nebbe) writes:
  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. One of the first things I do when a C program misbehaves is to check
  25. the trivial pitfalls.  One of the things I look for is "compound
  26. statements" that aren't the direct object for some control-flow
  27. construct.  If I used C more frequently, I would be tempted to 
  28. write a preprocessor which flagged such things.  In this case,
  29. such a preprocessor would issue a warning that the `{' and `}'
  30. were redundant.
  31.  
  32. Without explicitly looking for the above type of error, or having
  33. an automated tool which looks for it on your behalf, this could be
  34. a difficult to find error.  The problem is that programmers look
  35. at code and *know* what it's supposed to do.  They tend to skim
  36. the code looking for glaring errors. They miss this sort of thing
  37. because it's next to invisible.  In a large code in which the location
  38. of the problem is not easy to determine (like maybe this is in one
  39. of 500 routines which *could* be causing the problem), this could
  40. take some time to isolate.
  41.  
  42. Now, I think that the "compound statement" is a poor language design
  43. feature.  This is one of the reasons I think so.  Therefore, it's one
  44. of the features I'm most suspicious of when code goes wrong.  I would
  45. prefer that C would have the following style syntax:
  46.  
  47.    int x
  48.    ...
  49.    x = 1
  50.    while (x <= 10)
  51.       printf("%d\n", x)
  52.       x++
  53.    endwhile
  54.  
  55. Now there's no way to mix-up where the `while' loop terminates.
  56. The code is much easier to read and will have significantly
  57. fewer errors of the "I know what this means, but it's not doing
  58. it" variety.
  59.  
  60. -- 
  61. J. Giles
  62.