From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,4b06f8f15f01a568 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Software landmines (was: Why C++ is successful) Date: 1998/09/01 Message-ID: <6sh2ej$o9e@sjx-ixn1.ix.netcom.com>#1/1 X-Deja-AN: 386811831 References: <6rnhhe$e2u$1@nnrp1.dejanews.com> <6rsg0d$pcj@dfw-ixnews3.ix.netcom.com> <35eca5d9.4354839@news.geccs.gecm.com> Organization: ICGNetcom X-NETCOM-Date: Tue Sep 01 8:04:51 AM PDT 1998 Newsgroups: comp.lang.ada Date: 1998-09-01T08:04:51-07:00 List-Id: Brian, Silly indeed! I do not appreciate your use of the pejorative "silly" in response to my postingsince it seems to be a deliberate insult. I do admit that my hastily composed example could have been coded with more clarity. It did not occur to me that I would need to submit a perfect code example to make such a simple point but, since martinets abound, I submit a new, probably unnecessary, example. In case you have missed my original point in your zeal to criticize the code fragment, it is as follows: Ada is designed to encourage use of the assignment statement if we also want our code to be clear and readable. This was in response to Robert's (correct) assertion that programmers use assignment statements too liberally. I am appending your code example and mine in case some masochist wants to read it. I hope you understand that my example was not intended to represent real code. Perhaps the way I wrote the assignment statement confused you regarding my intentions. I concur that, if there is a simple algorithm, it can be stated as part of the declaration. In the kind of function I had in mind, there could be multiple possible values for the Result. In this case, the choice is between, Example (1) function F1 (paramter-list) return Result-type is Result : Result-type := initial-value; begin if condition-1 then Result := result-1; elsif condition-2 then Result := result-2; else Result := result-3; end if; return Result; end F1; versus Example(2) function F2 (paramter-list) return Result-type is begin if condition-1 then return result-1; elsif condition-2 then return result-2; else return result-3; end if; return Result; end F2; The two (simplified) functions epitomize the debate about a particular coding style. Example(2) illustrates how functions avoid using an extraneous assignment statement. Some practitioners prefer Example(1). I use both in my coding. It depends on the complexity of the function, my audience (everyone on the project is an ex-Fortranner), along with several helpings of intuition. Over the years I have found that Example(1) has been less error-prone and easier for the average programmer to maintain. Your mileage may vary according your experience. -- ==================== Original Postings ==================== -- What follows is my original message along with Mr. Orpin's -- rather impolite reply. -- =========================================================== In article <35eca5d9.4354839@news.geccs.gecm.com>, abuse@borpin.demon.co.uk (Brian Orpin) wrote: in response to the following code fragment submitted by me, >On Mon, 24 Aug 1998 19:47:31 GMT, Richard D Riehle > wrote: > >> Don't take away my assignment statements, Robert. The help me write >> crisp, short code sentences that ordinary mortals can understand. In >> fact, as an old time Fortranner, I sometimes write a function that >> looks like, > >> function F ( ... ) return some-data-type is >> Result : some-data-type := initial-value; >> begin >> Result := algorithmic-part; >> return Result; >> end F; > >Which of course is pretty silly . Result has a default value that is >never used. Could easily be written.. > >function F ( ... ) return some-data-type is > Result : some-data-type := algorithmic-part; >begin > return Result; >end F; > >or even > >function F ( ... ) return some-data-type is >begin > return algorithmic-part; >end F; > >YMMV