Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/18/84; site cca.UUCP Path: utzoo!watmath!clyde!burl!ulysses!bellcore!decvax!cca!g-rh From: g-rh@cca.UUCP (Richard Harter) Newsgroups: net.lang Subject: Re: and if you put this in your language ... Message-ID: <6699@cca.UUCP> Date: Sat, 15-Mar-86 18:19:26 EST Article-I.D.: cca.6699 Posted: Sat Mar 15 18:19:26 1986 Date-Received: Mon, 17-Mar-86 03:27:19 EST References: <1187@mmintl.UUCP> <> Reply-To: g-rh@cca.UUCP (Richard Harter) Organization: Computer Corp. of America, Cambridge Lines: 55 Summary: In article <> taylor@glasgow.UUCP (Jem Taylor) writes: > .................. > if (A) > { X; > if (B) Y; > else Z; > } > else Z; > >If Z is so large that it is not reasonable to have two copies of >it's code, it's time to make it a separate procedure anyway. > Sorry Jem, the code you suggest is wrong in principle even though it may be the right thing to do in practice as a matter of convenience, the principle bei: AVOID USING MULTIPLE COPIES OF THE SAME CODE Procedures are one way to avoid multiple copies. In any particular instance, however, creating another procedure may well be the wrong thing to do. The most general solution is to use a flag (which, as I recall, people were objecting to originally), e.g. flag = 0; if (A) { X; if (B) Y; else flag = 1; } else flag = 1; if (flag) Z; [I'm not in love with this code either.] If X, Y, and Z are large blocks of code one might also consider: xflag = 0; yflag = 0; zflag = 0; if (A) xflag = 1; else zflag = 1; if (xflag) { X; if (B) yflag = 1; else zflag = 1; } if (yflag) Y; if (zflag) Z; This is more long winded in schematic form. However it will be clearer if X, Y, and Z are complicated pieces of code. [All complaints about the above style of indentation will be forwarded to /dev/null or to Rich Rosen.] Richard Harter, SMDS Inc.