From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.5-pre1 (2020-06-20) on ip-172-31-74-118.ec2.internal X-Spam-Level: X-Spam-Status: No, score=-1.9 required=3.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.5-pre1 Date: 11 Dec 92 20:08:14 GMT From: alex@MIMSY.CS.UMD.EDU (Alex Blakemore) Subject: Re: Suggestion for multivalue boolean case for 9X Message-ID: <62774@mimsy.umd.edu> List-Id: dunbar@saifr00.cfsat.honeywell.com (Mark Dunbar) writes: > Using Ada83, instead of the nested if statement, one could do the following: > if ( not Cond_1 ) and ( not Cond_2 ) and ( not Cond_3 ) then > elsif ( not Cond_1 ) and ( not Cond_2 ) and ( Cond_3 ) then > elsif ( not Cond_1 ) and ( Cond_2 ) and ( not Cond_3 ) then > etc. I've rarely encountered complex nested if statements where every combination of conditions had a completely different action. More often, several combinations share the same action, or parts of the same action. In such cases, you can frequently improve things by combining and reordering tests - often removing a level of nesting. for a simple example, if x then if not x then if y then can be rewritten C; A; elsif y then else A; B; else end if; B; else end if; C; end if; (assuming the conditions are free of side effects) A single level chain of ordered condition/action pairs is much easier to reason about than any nested logic. I know it seems to picayune but I've found many errors by simplifying logical statements in mechanical ways like this - and almost always obtain a better understanding of the code as a side effect. This should be ingrained after CS 101 and not be worth mentioning in such an esteemed forum as comp.lang.ada but many programmers dont seem to take the time to find the the simplest construct. -- --------------------------------------------------- Alex Blakemore alex@cs.umd.edu NeXT mail accepted