comp.lang.ada
 help / color / mirror / Atom feed
From: cochiti.lanl.gov!jlg@lanl.gov  (J. Giles)
Subject: Re: FORTRAN bug(was Re: C++ vs. Ada -- Is Ada loosing?)
Date: 14 Dec 92 18:33:26 GMT	[thread overview]
Message-ID: <1992Dec14.183326.27689@newshost.lanl.gov> (raw)

In article <1992Dec11.163811@lglsun.epfl.ch>, nebbe@lglsun.epfl.ch (Robb Nebbe)
 writes:
|> Michael Feldman:
|> 
|>    int x;
|>    ...
|>    x = 1;
|>    while (x <= 10);
|>    { 
|>       printf("%d\n", x);
|>       x++;
|>    }

One of the first things I do when a C program misbehaves is to check
the trivial pitfalls.  One of the things I look for is "compound
statements" that aren't the direct object for some control-flow
construct.  If I used C more frequently, I would be tempted to 
write a preprocessor which flagged such things.  In this case,
such a preprocessor would issue a warning that the `{' and `}'
were redundant.

Without explicitly looking for the above type of error, or having
an automated tool which looks for it on your behalf, this could be
a difficult to find error.  The problem is that programmers look
at code and *know* what it's supposed to do.  They tend to skim
the code looking for glaring errors. They miss this sort of thing
because it's next to invisible.  In a large code in which the location
of the problem is not easy to determine (like maybe this is in one
of 500 routines which *could* be causing the problem), this could
take some time to isolate.

Now, I think that the "compound statement" is a poor language design
feature.  This is one of the reasons I think so.  Therefore, it's one
of the features I'm most suspicious of when code goes wrong.  I would
prefer that C would have the following style syntax:

   int x
   ...
   x = 1
   while (x <= 10)
      printf("%d\n", x)
      x++
   endwhile

Now there's no way to mix-up where the `while' loop terminates.
The code is much easier to read and will have significantly
fewer errors of the "I know what this means, but it's not doing
it" variety.

-- 
J. Giles

             reply	other threads:[~1992-12-14 18:33 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1992-12-14 18:33 J. Giles [this message]
  -- strict thread matches above, loose matches on Subject: below --
1992-12-18 21:56 FORTRAN bug(was Re: C++ vs. Ada -- Is Ada loosing?) Michael Feldman
1992-12-18  9:22 agate!spool.mu.edu!uwm.edu!zaphod.mps.ohio-state.edu!caen!uvaarpa!vger.ns
1992-12-16 17:40 Pascal Obry
1992-12-16 16:02 fred j mccall 575-3539
1992-12-15 16:36 enterpoop.mit.edu!bloom-picayune.mit.edu!mintaka.lcs.mit.edu!ogicse!uwm.e
1992-12-15  2:57 Michael Feldman
1992-12-15  2:43 Michael Feldman
1992-12-14 22:15 John Bollenbacher
1992-12-14 17:04 agate!spool.mu.edu!yale.edu!qt.cs.utexas.edu!cs.utexas.edu!csc.ti.com!til
1992-12-14 17:00 agate!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
1992-12-14 16:55 agate!spool.mu.edu!sdd.hp.com!zaphod.mps.ohio-state.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mksol!mccall
1992-12-12 17:53 Michael Feldman
1992-12-12 14:34 Fergus Jam es HENDERSON
1992-12-12 14:20 Fergus Jam es HENDERSON
1992-12-12  6:04 Bob Kitzberger
1992-12-12  0:42 Pascal Obry
1992-12-11 23:22 Tucker Taft
1992-12-11 22:24 John Nestoriak III
1992-12-11 21:31 Michael Feldman
1992-12-11 21:04 Tucker Taft
1992-12-11 15:38 Robb Nebbe
1992-12-11 13:29 agate!spool.mu.edu!uwm.edu!cs.utexas.edu!csc.ti.com!tilde.csc.ti.com!mkso
1992-12-09  6:02 Michael Feldman
1992-12-08 17:25 J. Giles
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox