comp.lang.ada
 help / color / mirror / Atom feed
* bug me now / bug me later
@ 1990-06-07 23:26 Jim Harkins
  1990-06-08 16:51 ` Charles H. Sampson
                   ` (2 more replies)
  0 siblings, 3 replies; 6+ messages in thread
From: Jim Harkins @ 1990-06-07 23:26 UTC (permalink / 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.

^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~1990-06-14 15:00 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1990-06-07 23:26 bug me now / bug me later Jim Harkins
1990-06-08 16:51 ` 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

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