comp.lang.ada
 help / color / mirror / Atom feed
From: miker3@ix.netcom.com (Mike Rubenstein)
Subject: Re: ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada)
Date: 1996/04/21
Date: 1996-04-21T08:35:54-05:00	[thread overview]
Message-ID: <317a3715.38162294@nntp.ix.netcom.com> (raw)
In-Reply-To: 01bb2ed2.425fb900$65c2b7c7@Zany.localhost

Bradd W. Szonye <bradds@ix.netcom.com> wrote:

> Try to keep in mind the spirit of defensive programming:
> If there's something ambiguous about the way you could implement
> something, and one implementation is safe regardless of how you interpret
> the ambiguity, the other implementation only works under one specific
> interpretation, then defensive programming (and portable programming) will
> encourage the code that works under all circumstances. Consider:
> 
> for (size_t i = 0; i < 10; i++) do_stuff();
> 
> versus
> 
> for (size_t i = 0; i != 10; i++) do_stuff();
> 
> Even though you *know* that i will never be greater than 10, even though
> "not equals" should always stop the loop after the tenth iteration,
> practically every programmer will write the first loop in preference to
> the second. This has nothing to do with standards; the standards say that
> i is a local, stack-based variable, not global, and since it is not
> volatile or referenced by anything else, do_stuff() couldn't modify it,
> even another thread couldn't modify it. But should your memory chips fail,
> or do_stuff() accidentally trash the stack with a pointer, then the first
> loop will never let i get out of the range of 0 <= i < 10, while the
> second loop might.

What nonsense.  Most programmers write the loop the first way out of
habit and for consistency.  Suppose we change the loop a little:

	for (size_t i = a; i < 10; i++) do_stuff();
 
versus
 
	for (size_t i = a; i != 10; i++) do_stuff();

Now the loops mean different things.  Either might be correct, but the
first is by far the more common.

If the stack is trashed or the memory chips have failed, why do you
want to get out of the loop?  Why do you assume that getting out of
the loop prematurely is better than not getting out of it at all?
Suppose the loop is part of a sort.  If you stay in it, the program
will hang and the user will complain.  If you exit it the program may
continue and output erroneous information that causes costly errors.

Defensive programming is important, but coding so you'll exit a loop
even if the hardware fails has nothing to do with it.


Michael M Rubenstein




  reply	other threads:[~1996-04-21  0:00 UTC|newest]

Thread overview: 177+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1996-04-12  0:00 ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada) Chuck Karish
1996-04-11  0:00 ` Robert Dewar
1996-04-20  0:00   ` Bradd W. Szonye
1996-04-21  0:00     ` Mike Rubenstein [this message]
1996-04-22  0:00       ` Tom Payne
1996-04-22  0:00         ` Peter Seebach
1996-04-21  0:00     ` Danette & Murray Root
1996-04-23  0:00       ` Bradd W. Szonye
     [not found] <JSA.96Feb16135027@organon.com>
1996-03-26  0:00 ` C/C++ knocks the crap out of Ada Ed Falis
1996-03-28  0:00   ` Kevin Cline
1996-03-30  0:00     ` Jon S Anthony
1996-04-01  0:00       ` Kevin Cline
1996-04-02  0:00         ` Lawrence Kirby
1996-04-02  0:00           ` ANSI C and POSIX (was Re: C/C++ knocks the crap out of Ada) David Emery
1996-04-02  0:00             ` The Right Reverend Colin James III
1996-04-03  0:00               ` Bill Clinton
1996-04-03  0:00               ` David Emery
1996-04-03  0:00                 ` The Right Reverend Colin James III
1996-04-04  0:00                   ` Dan Pop
1996-04-04  0:00             ` Lawrence Kirby
1996-04-05  0:00               ` Robert Dewar
1996-04-05  0:00                 ` Lawrence Kirby
1996-04-05  0:00                   ` Robert Dewar
1996-04-06  0:00                     ` Peter Seebach
1996-04-06  0:00                       ` Robert Dewar
1996-04-16  0:00                       ` Philip Brashear
1996-04-16  0:00                         ` Robert Dewar
1996-04-19  0:00                           ` Chuck Karish
1996-04-05  0:00                 ` Peter Seebach
1996-04-05  0:00                   ` Robert Dewar
1996-04-06  0:00                     ` Lawrence Kirby
1996-04-06  0:00                       ` Robert Dewar
1996-04-07  0:00                         ` Lawrence Kirby
1996-04-10  0:00                           ` halvin
1996-04-10  0:00                             ` Peter Seebach
1996-04-11  0:00                             ` Dan Pop
1996-04-12  0:00                             ` Chuck Karish
1996-04-12  0:00                         ` Chuck Karish
1996-04-12  0:00                           ` Robert Dewar
1996-04-13  0:00                             ` Chuck Karish
1996-04-13  0:00                               ` Robert Dewar
1996-04-13  0:00                                 ` Peter Seebach
1996-04-13  0:00                                   ` Robert Dewar
1996-04-14  0:00                                     ` Lawrence Kirby
1996-04-15  0:00                                     ` Chuck Karish
1996-04-15  0:00                                 ` Chuck Karish
1996-04-16  0:00                                   ` Robert Dewar
1996-04-16  0:00                                     ` Chuck Karish
1996-04-16  0:00                                       ` Robert Dewar
1996-04-12  0:00                     ` Chuck Karish
1996-04-11  0:00                       ` Kazimir Kylheku
1996-04-12  0:00                         ` Chuck Karish
1996-04-12  0:00                           ` Kazimir Kylheku
1996-04-12  0:00                         ` Tom Griest
1996-04-12  0:00                           ` Robert Dewar
1996-04-12  0:00                       ` Robert Dewar
1996-04-13  0:00                         ` Chuck Karish
1996-04-13  0:00                           ` David Emery
1996-04-22  0:00                         ` Mike McCarty
1996-04-22  0:00                           ` David Emery
1996-04-05  0:00               ` David Emery
1996-04-06  0:00                 ` Lawrence Kirby
1996-04-06  0:00 ` Dan Pop
1996-04-07  0:00   ` Robert Dewar
1996-04-07  0:00     ` Peter Seebach
1996-04-08  0:00       ` Robert Dewar
1996-04-08  0:00         ` Lawrence Kirby
1996-04-08  0:00           ` Szu-Wen Huang
1996-04-08  0:00             ` James McIninch
1996-04-08  0:00               ` Szu-Wen Huang
1996-04-08  0:00                 ` Robert Dewar
1996-04-19  0:00                   ` Bradd W. Szonye
1996-04-08  0:00               ` Fergus Henderson
1996-04-08  0:00                 ` Robert Dewar
1996-04-19  0:00                 ` Bradd W. Szonye
1996-04-20  0:00                   ` Fergus Henderson
1996-04-20  0:00                     ` Bradd W. Szonye
1996-04-08  0:00               ` Robert Dewar
1996-04-11  0:00                 ` Keith Thompson
1996-04-19  0:00                 ` Bradd W. Szonye
1996-04-08  0:00           ` Robert Dewar
1996-04-08  0:00             ` Peter Seebach
1996-04-09  0:00               ` Robert Dewar
1996-04-09  0:00                 ` Peter Seebach
1996-04-09  0:00                 ` Kazimir Kylheku
1996-04-08  0:00             ` Kazimir Kylheku
1996-04-09  0:00               ` Robert Dewar
1996-04-09  0:00                 ` Kazimir Kylheku
1996-04-09  0:00                   ` Robert Dewar
1996-04-09  0:00                     ` Kazimir Kylheku
1996-04-10  0:00                       ` Robert Dewar
1996-04-10  0:00                         ` Kazimir Kylheku
1996-04-10  0:00                           ` Robert A Duff
1996-04-19  0:00                           ` Bradd W. Szonye
1996-04-19  0:00                             ` Robert Dewar
1996-04-23  0:00                               ` Bradd W. Szonye
1996-04-10  0:00                 ` Mike Shannon
1996-04-09  0:00                   ` Robert Dewar
1996-04-09  0:00                     ` Peter Seebach
1996-04-10  0:00                       ` Robert Dewar
1996-04-09  0:00                   ` Robert Dewar
1996-04-11  0:00                   ` Tom Wheeley
1996-04-11  0:00                     ` Robert Dewar
1996-04-11  0:00                     ` Robert A Duff
1996-04-12  0:00                       ` Tom Wheeley
1996-04-12  0:00                         ` Robert Dewar
1996-04-13  0:00                           ` Chuck Karish
1996-04-13  0:00                             ` Robert Dewar
1996-04-19  0:00                               ` Bradd W. Szonye
1996-04-19  0:00                                 ` David Emery
1996-04-19  0:00                                 ` Robert Dewar
1996-04-22  0:00                                   ` Peter Seebach
1996-04-23  0:00                                 ` Keith Thompson
1996-04-19  0:00                       ` Bradd W. Szonye
1996-04-19  0:00                         ` Robert Dewar
1996-04-23  0:00                           ` Bradd W. Szonye
1996-04-19  0:00                         ` Robert A Duff
1996-04-20  0:00                           ` Bradd W. Szonye
1996-04-09  0:00             ` Robert I. Eachus
1996-04-09  0:00               ` Kazimir Kylheku
1996-04-09  0:00               ` Peter Seebach
1996-04-25  0:00               ` BLUE
1996-04-08  0:00         ` Peter Seebach
1996-04-08  0:00           ` Fergus Henderson
1996-04-08  0:00             ` Peter Seebach
1996-04-09  0:00               ` Robert Dewar
1996-04-09  0:00               ` Fergus Henderson
1996-04-09  0:00                 ` Kenneth Mays
1996-04-10  0:00                   ` Fergus Henderson
1996-04-10  0:00                 ` Tom Payne
1996-04-09  0:00               ` Fergus Henderson
1996-04-09  0:00                 ` Robert Dewar
1996-04-09  0:00                   ` Kazimir Kylheku
1996-04-08  0:00             ` Robert Dewar
1996-04-08  0:00               ` Kazimir Kylheku
1996-04-09  0:00                 ` Robert Dewar
1996-04-11  0:00                   ` Tom Wheeley
1996-04-11  0:00                     ` Kazimir Kylheku
1996-04-12  0:00                       ` Peter Seebach
1996-04-13  0:00                       ` Tom Wheeley
1996-04-09  0:00               ` Peter Seebach
1996-04-10  0:00             ` Steve Summit
1996-04-10  0:00               ` Robert Dewar
1996-04-08  0:00           ` Robert Dewar
1996-04-08  0:00             ` Kazimir Kylheku
1996-04-09  0:00               ` Robert Dewar
1996-04-09  0:00                 ` Lawrence Kirby
1996-04-09  0:00                   ` Robert Dewar
1996-04-09  0:00                     ` Kazimir Kylheku
1996-04-10  0:00                       ` Robert Dewar
1996-04-10  0:00                         ` Kazimir Kylheku
1996-04-10  0:00                     ` David Emery
1996-04-09  0:00                 ` Kazimir Kylheku
1996-04-09  0:00             ` Peter Seebach
1996-04-10  0:00             ` John Marshall
1996-04-10  0:00               ` Robert Dewar
1996-04-09  0:00           ` Steve Tynor
1996-04-09  0:00             ` Kazimir Kylheku
1996-04-10  0:00             ` Chet
1996-04-10  0:00               ` Tom Watson
1996-04-10  0:00               ` Robert Dewar
1996-04-10  0:00               ` Peter Seebach
1996-04-10  0:00               ` Kazimir Kylheku
1996-04-10  0:00             ` Lawrence Kirby
1996-04-12  0:00               ` Dr S.J. Harris
1996-04-12  0:00                 ` Peter Seebach
1996-04-12  0:00           ` Gareth Rees
1996-04-10  0:00         ` Matt Austern
1996-04-10  0:00           ` Robert Dewar
1996-04-10  0:00         ` Tom Payne
1996-04-07  0:00     ` Lawrence Kirby
1996-04-07  0:00       ` Robert Dewar
1996-04-08  0:00         ` Peter Seebach
1996-04-08  0:00           ` Robert Dewar
1996-04-08  0:00             ` Peter Seebach
1996-04-09  0:00             ` Dan Pop
1996-04-09  0:00               ` James McIninch
1996-04-10  0:00                 ` Dan Pop
1996-04-09  0:00                   ` Danette & Murray Root
1996-04-11  0:00                 ` Tom Wheeley
1996-04-07  0:00     ` Dan Pop
1996-04-07  0:00       ` Robert Dewar
replies disabled

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