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=0.7 required=5.0 tests=BAYES_00,MSGID_RANDY autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,5265ce03ee8f5252 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-01-04 08:00:15 PST Path: supernews.google.com!sn-xit-02!supernews.com!news.infoave.net!cyclone-sjo1.usenetserver.com!news-out.usenetserver.com!newsfeed.skycache.com!Cidera!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: n_brunot@my-deja.com Newsgroups: comp.lang.ada Subject: Re: Ok sorry, it is just a book gives no feedback. Date: Thu, 04 Jan 2001 15:49:58 GMT Organization: Deja.com Message-ID: <932632$e0e$1@nnrp1.deja.com> References: <931r2l$4ai5t$2@ID-25716.news.dfncis.de> <931t08$5u5$1@nnrp1.deja.com> NNTP-Posting-Host: 212.27.48.102 X-Article-Creation-Date: Thu Jan 04 15:49:58 2001 GMT X-Http-User-Agent: Mozilla/5.0 (Windows; U; WinNT4.0; fr-FR; m18) Gecko/20001106 Netscape6/6.0 X-Http-Proxy: 1.1 x66.deja.com:80 (Squid/1.1.22) for client 212.27.48.102 X-MyDeja-Info: XMYDJUIDn_brunot Xref: supernews.google.com comp.lang.ada:3655 Date: 2001-01-04T15:49:58+00:00 List-Id: In article <931t08$5u5$1@nnrp1.deja.com>, Robert Dewar wrote: > In article <931r2l$4ai5t$2@ID-25716.news.dfncis.de>, > "Nick Roberts" wrote: > > > My own opinion is that, generally, functions should have no > > side effects > > This principle is in general a reasonable one, but it is not > easy to define what this means. Nick goes on to give an > explanation, but his explanation is wrong, it would forbid > many functions, e.g. anything that allocates and returns a > pointer, which is far too severe. > Well "generally" seems reasonable and never said that this behavior is forbidden. Of course some functions must have side effects, but I agree it's better to avoid it each time side effects are not necessary. Just look the following code (simplified from old buggy code). Depending if the compiler evaluate right or left term first for "&", you get quite different behavior .... This is a pathologic case, but good example to show why it's not so bad to avoid side effect each time you can, and keep constantly testing your code on different Ada compilers ... with Text_Io; procedure Test is N : Natural := 10; function Decrement return String is begin N := N - 1; return "A"; end; function Recursive return String is begin if N /= 0 then return Decrement & Recursive; else return "A"; end if; end; begin Text_Io.Put_Line (Recursive); end; Sent via Deja.com http://www.deja.com/