From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: * X-Spam-Status: No, score=1.1 required=5.0 tests=BAYES_40,INVALID_DATE, MSGID_SHORT autolearn=no autolearn_force=no version=3.4.4 Xref: utzoo comp.lang.c:29447 comp.lang.ada:3916 Path: utzoo!attcan!uunet!seismo!ukma!rex!samsung!usc!ucsd!helios.ee.lbl.gov!nosc!crash!ncr-sd!sagpd1!jharkins From: jharkins@sagpd1.UUCP (Jim Harkins) Newsgroups: comp.lang.c,comp.lang.ada Subject: bug me now / bug me later Keywords: philosophical differences Message-ID: <811@sagpd1.UUCP> Date: 7 Jun 90 23:26:24 GMT Organization: Scientific Atlanta-GPD, San Diego X-Local-Date: 7 Jun 90 16:26:24 PDT List-Id: 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.