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 09:20:17 PST Path: supernews.google.com!sn-xit-02!supernews.com!newsfeed.direct.ca!look.ca!news.maxwell.syr.edu!nntp2.deja.com!nnrp1.deja.com!not-for-mail From: Robert Dewar Newsgroups: comp.lang.ada Subject: Re: Ok sorry, it is just a book gives no feedback. Date: Thu, 04 Jan 2001 17:09:04 GMT Organization: Deja.com Message-ID: <932an8$ijs$1@nnrp1.deja.com> References: <931r2l$4ai5t$2@ID-25716.news.dfncis.de> <931t08$5u5$1@nnrp1.deja.com> <932632$e0e$1@nnrp1.deja.com> NNTP-Posting-Host: 205.232.38.14 X-Article-Creation-Date: Thu Jan 04 17:09:04 2001 GMT X-Http-User-Agent: Mozilla/4.61 [en] (OS/2; U) X-Http-Proxy: 1.0 x61.deja.com:80 (Squid/1.1.22) for client 205.232.38.14 X-MyDeja-Info: XMYDJUIDrobert_dewar Xref: supernews.google.com comp.lang.ada:3658 Date: 2001-01-04T17:09:04+00:00 List-Id: In article <932632$e0e$1@nnrp1.deja.com>, n_brunot@my-deja.com wrote: > 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; This would be horrible code even if procedures were used. Global variables in general are harmful if not very carefully used. You argue that functions should not have side effects, and then use as an example a very poorly written junk function. The point is that there are plenty of legitimate functions that have side effects in the sense in which they were defined here. E.g. A function that takes two pointers to strings and returns a pointer to their concatenation is quite reasonable, but has side effects according to this definition. Note that ANY allocation has a side effect, so these rules about functions would say that no functions can ever do allocations. That's an unreasonable restriction! Sent via Deja.com http://www.deja.com/