comp.lang.ada
 help / color / mirror / Atom feed
From: jharkins@sagpd1.UUCP (Jim Harkins)
Subject: bug me now / bug me later
Date: 7 Jun 90 23:26:24 GMT	[thread overview]
Message-ID: <811@sagpd1.UUCP> (raw)


Lets say you have the following (you ADA people, please bear with me):

	#define SIZE	6
	#define STEP	2

Which is better:

	a.	for(i = SIZE; i != 0; i -= STEP)
or
	b.	for(i = SIZE; i > 0; i -= STEP)

Where this makes a difference is suppose SIZE is changed to 7.  Obviously
'a' goes into an infinite loop, while 'b' stops.  In the real world SIZE and
STEP could be variables that have been input by a user and manipulated a
gazillion times before being used in the for loop.

With method 'a' a bug is easy to spot, thus easy to fix.  But the bug may not
appear at a good time, the user may prefer that his system limp along rather
than hang completely.

With method 'b' the bug is harder to spot.  If you test your code well you
should catch these things, but a man named Murphy became famous anyway.  I
believe method 'b' is preferred by 'defensive programmers'.  It is also
possible that with method 'b' the loop body stomps over somebody elses
memory, with unknown but probably bad results.


So, how do you all feel about this?  As I'm writing for a military contract
I've cross-posted this to comp.lang.ada, I hope they don't get too upset.  And
please hurry, this came up for a reason :-)


-- 
jim		jharkins@sagpd1

I hate to see you go, but I love to see you walk away.

             reply	other threads:[~1990-06-07 23:26 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1990-06-07 23:26 Jim Harkins [this message]
1990-06-08 16:51 ` bug me now / bug me later Charles H. Sampson
1990-06-11 22:19 ` Wade Richards
1990-06-12 13:36 ` Robert Firth
1990-06-14  5:22   ` brnstnd
1990-06-14 15:00     ` David Kassover
replies disabled

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