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: 10 Apr 93 01:03:55 GMT From: sampson@cod.nosc.mil (Charles H. Sampson) Subject: Re: and then Message-ID: <1993Apr10.010355.4244@nosc.mil> List-Id: In article <1993Apr9.180808.19494@scf.loral.com> bashford@srs.loral.com (Dave B ashford) writes: >In article <1q29bd$7d8@huon.itd.adelaide.edu.au> andrewd@cs.adelaide.edu.au wr ites: >>There could well be cases where evaluation of both operands is wanted >>(if evaluation of one or both has a desired side-effect). If so, >>"optimising" evaluation of one away is highly undesirable. > >I can't believe my eyes - "desired side-effect" in Ada ? Several people >have mentioned side-effects as a reason not to optimize boolean >expressions. I thought one of the guiding principles of good s/w >engineering was to minimize or eliminate side-effects. The only reason >I can think of not to optimize to short circuit forms is to catch >undesired side-effects. > > ... > >Are there "desired side-effects" ? I assume you're referring to side effects of function references. Procedures almost always have desirable side effects. In the original requirements for Ada (Steelman), functions were not allowed to have side effects. At least one of the candidate languages, Blue if I remember correctly, took a stab at prohibiting them with rules about exactly what kind of code a function could and could not contain. Somewhere along the way the requirement vanished, either by explicit action or benign neglect, probably because the requirement was considered draconi- an. By that time I was pretty far out of the loop. Back to the question. In my programming style, a function is a sub- program whose _primary_ purpose is the calculation of a single value and a procedure is a subprogram whose _primary_ purpose is performing an action. (There's an unfortunate grey area in applying these rules.) This allows for functions that have side effects and procedures that have only one formal parameter, of mode OUT. I tend to minimize the side effects of functions, but I don't rule them out. For example, in processing a character stream, I prefer to have a function named Next_character that returns the next character from the stream and moves the stream cursor so that character becomes the previous character, rather than a procedure named Get. Charlie