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,35d52809fb2aac8f X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!z6g2000pre.googlegroups.com!not-for-mail From: Adam Beneschan Newsgroups: comp.lang.ada Subject: Re: Naming convention to identify functions with side effects Date: Mon, 29 Sep 2008 11:55:49 -0700 (PDT) Organization: http://groups.google.com Message-ID: <29ac62e1-78da-4048-ad95-8f88a29f7d31@z6g2000pre.googlegroups.com> References: <5654ee5f-aa9f-4fff-87e0-45854b850f26@y38g2000hsy.googlegroups.com> NNTP-Posting-Host: 66.126.103.122 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1222714550 20350 127.0.0.1 (29 Sep 2008 18:55:50 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 29 Sep 2008 18:55:50 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: z6g2000pre.googlegroups.com; posting-host=66.126.103.122; posting-account=duW0ogkAAABjRdnxgLGXDfna0Gc6XqmQ User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.7.12) Gecko/20050922 Fedora/1.7.12-1.3.1,gzip(gfe),gzip(gfe) Xref: g2news1.google.com comp.lang.ada:2142 Date: 2008-09-29T11:55:49-07:00 List-Id: On Sep 29, 11:17 am, Hibou57 (Yannick Duch=EAne) wrote: > Hello every body out there, > > Do some one know a commonly used or at least a good, naming convention > to identify functions with side effects ? I don't. But I'll take advantage of this to discuss one thing that I think is a REALLY BAD IDEA. To me, "functions with side effects" can encompass at least three different types of functions, and perhaps the answer to your question should be different for all three: (1) Functions that really are (mathematically) functions, and that will return the same value each time you call them with the same parameters, but they may also save some state information in order to help make the next execution run faster. (2) Functions whose purpose is to return a value, but that can return different values each time they're called. An example would be a random number generator function that returns a different value each time it's called, or a function whose purpose is to return the "next" word from a file, so that successive calls to the function return successive values from the file. (3) "Functions" whose purpose is to perform some task, and that also return a value but only as a secondary purpose or a result indicator. This is sometimes a little harder to do in Ada than other languages, because functions can't have OUT or IN OUT parameters, but it's still possible. A common usage I've seen is to have a function that, say, opens a file and returns a Boolean to indicate whether the operation was successful. I think you can make a case that you shouldn't write this as a function; nevertheless, it's commonly done (yes, I do it sometimes). It's this last that is connected to one of my pet peeves. Say you've decided to write a routine to load a particular web page, and you've made it a Boolean function that returns True if it's successful: function Load_Web_Page (URL : String) return Boolean; Several times, I've heard people say (in similar cases) that the name should be something like this: function Web_Page_Is_Loaded (URL : String) return Boolean; so that it's grammatically correct when you put it in an IF statement: if Web_Page_Is_Loaded ("http://www.irvine.com") then... This is WRONG, WRONG, WRONG!!! It may make your IF statement look more grammatically correct, but it OBSCURES what the program is doing. The above "grammatically correct" statement looks more like a check to see if the page is already loaded; a programmer reading this will not be able to figure out that the function call is the routine that actually does the loading. This is much better: if Load_Web_Page ("http://www.irvine.com") then... because now the reader knows that this call is actually loading the web page, even if it violates a rule of English grammar. So while I don't have a good answer to your question, I *can* tell you that if anyone says that a Boolean function should *always* have a name that is an adjective, or a past participle, or a predicate, rather than just a verb, don't listen to them. Thank you for patiently sitting through my rant. -- Adam