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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Thread: 103376,8f802583e5c84fa X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!news.glorb.com!news.banetele.no!news.szn.dk!news.jacob-sparre.dk!pnx.dk!not-for-mail From: Jacob Sparre Andersen Newsgroups: comp.lang.ada Subject: Re: String filtering Date: Mon, 03 Oct 2005 09:44:10 +0200 Organization: Jacob's private Usenet server Message-ID: References: <1j92wa9843ylq.16j89wuqatbaj$.dlg@40tude.net> <1b54lwg8s1gk8.1t3jp1cmc2x32$.dlg@40tude.net> <1128236249.692858.50370@g14g2000cwa.googlegroups.com> NNTP-Posting-Host: hugin.crs4.it Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: jacob-sparre.dk 1128325453 8161 156.148.71.67 (3 Oct 2005 07:44:13 GMT) X-Complaints-To: sparre@jacob-sparre.dk NNTP-Posting-Date: Mon, 3 Oct 2005 07:44:13 +0000 (UTC) User-Agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux) Cancel-Lock: sha1:0MA90x31Xn7S715AYBjR70MdV10= Xref: g2news1.google.com comp.lang.ada:5348 Date: 2005-10-03T09:44:10+02:00 List-Id: Robert A Duff wrote: > Steve Whalen wrote: >> I seem to have been brainwashed into thinking that functions with >> side effects of any kind were a "bad thing", especially in a >> language like Ada. > > I think that side effects in functions are usually a bad idea. > But not always. My whole understanding of the concept "a function" is that it doesn't have side effects. - But I'm a mathematician (and physicist), not a computer scientist. > I think the programmer, not the language designer, should make such > decisions. I like restrictive rules that prevent me (as a > programmer) from doing bad things by accident. But I don't like > restrictive rules that try to prevent me from doing things I > deliberately choose to do. The problem is then to introduce a way to make it clear if you want a function to have side effects or not. Just coding a function with side effects isn't the most clear way to do it (although using an "in out" parameter is pretty close). Would it be to go too far to have to specify functions as either: function Name (...) return Subtype; or: function Name with side effects (...) Subtype; I know that new keywords aren't exactly popular, but I hope the basic idea still is clear. It might be possible to do something similar with a pragma, but I would prefer to have it more explicit in the declaration of the function. Introducing a clear separation of functions in those which can have side effects and those which can't have side effects, might also allow us to tighten the current, somewhat lax definition of functions without side effects. > We can solve this in Ada by adding various levels of indirection, > which is rather a pain. For example, the "Rosen trick". Would it be possible to tighten the rules for functions without side effects to prevent the "Rosen trick"? Or will that workaround effectively always be possible? > Another example of side effects that I think are OK is when you're > getting items from a stream. Agreed. But I wouldn't mind being forced to document that the function had side effects. > Both 'out' and 'in out' should be allowed. If I ran the circus, I > would also require some sort of syntactic indication on the _call_ > for '[in] out' parameters. For both procedures and functions. That might make more sense than just indicating it in the declaration. > P.S. "Side effect" is a pejorative term. (Some drug cures your > disease, but makes you nauseous.) If the effect is intended by the > programmer, and clear in the code, perhaps we should call it an > "effect", without the "side". "Effect" is not quite clear enough. "Global effect" might be to exaggerate a bit. "Modifying function"? Greetings, Jacob -- "Three can keep a secret if two of them are dead."