home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!hri.com!noc.near.net!news.Brown.EDU!qt.cs.utexas.edu!cs.utexas.edu!swrinde!sdd.hp.com!hpscit.sc.hp.com!scd.hp.com!hpscdm!hplextra!hpcss01!hpcupt1!jamiller
- From: jamiller@hpcupt1.cup.hp.com (Jim Miller)
- Newsgroups: comp.lang.c
- Subject: Re: Help - What Is Wrong?
- Message-ID: <138740001@hpcupt1.cup.hp.com>
- Date: 13 Nov 92 00:36:58 GMT
- References: <720002131.AA03045@csource.oz.au>
- Organization: Hewlett Packard, Cupertino
- Lines: 61
-
- >comp.lang.c / mjs@hubcap.clemson.edu (M. J. Saltzman)
- >
- >Presumably, "i != 5" is "less safe" because a failure of the initial
- >condition to satisfy i < 5 will not result in an infinite loop
- >(especially if the initializer "i = 0" is replaced by, say, "i = j + 1",
- >or if the initial i is passed as a parameter). On the other hand,
- >this may not be the best kind of "safety" to have.
- >
- >In _The_Science_of_Programming_[1], David Gries argues that the guards
- >on loops should be as weak as possible, so that if the initial
- >condition is violated, the program will fail catastrophically (i.e.
- >with an infinite loop).
-
- IMHO: yes and no.
-
- While unit testing, "i != 5" might be the better idea for the reasons stated,
- for *production* I'd choose "i < 5". If the program can continue to limp
- along instead of crash/hang, the user may still be able to use it,
- they may be able to save their data, they may even be able to survive.
-
- I agree that for OS code the policy of "if anything is wrong: DIE
- immediately" is the best policy, but I don't like applications that do that.
-
- Just *why* do you want the user to have an application that hangs when the
- task presently being performed might be a minor one?
-
- The risk to user data will be, in general, no worse for continuing
- than for aborting/hanging immediately. (This is based upon absolutely
- no data what so ever :-).
-
- I usually have a backup of my old data, it's my work of the last 2 hours
- that I want a *chance* to save.
-
- An immediate halt/hang *will* cause loss of all currently changed data.
- In the middle of many change operations, it *will* cause the data to
- be useless.
-
- Continuing may, or may not, cause loss of data. Immediate halt/hang will,
- however, should prevent any data from getting back to the disk (or other
- device), which is why for OS code it may be the best policy (I don't want
- my directories corrupted :-().
-
- Think of real life: do you want your car to halt in the middle of nowhere
- because the oil is low, or do you want it to tell you (using an idiot
- light) that something is bad and let you take the corrective action?
-
- Note: in critical situations the argument changes. While inserting
- control rods in a nuclear reactor, I want the program to continue,
- while removing control rods I want it to hang or abort -- except that
- I do NOT want it to loop forever on "remove control rod i, i+1, i+2, etc".
-
- Ok, David Gries and I disagree.
- So, an expert and I disagree.
- So, what else is new? :-)
-
-
- jim miller
- jamiller@cup.hp.com
- (a.k.a James A. Miller; Jim the JAM; stupid; @!?$$!; ... )
- Anything I say will be used against me ...
- But my company doesn't know or approve or condone anything of mine here.
-