home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!think.com!ames!haven.umd.edu!mimsy!alex
- From: alex@cs.umd.edu (Alex Blakemore)
- Newsgroups: comp.lang.ada
- Subject: Re: Suggestion for multivalue boolean case for 9X
- Message-ID: <62774@mimsy.umd.edu>
- Date: 11 Dec 92 20:08:14 GMT
- References: <dnsurber.724028252@node_26400> <1992Dec11.011515.2859@saifr00.cfsat.honeywell.com>
- Sender: news@mimsy.umd.edu
- Organization: U of Maryland, Dept. of Computer Science, Coll. Pk., MD 20742
- Lines: 44
-
- 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
-