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.3 required=5.0 tests=BAYES_00, REPLYTO_WITHOUT_TO_CC autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,35d52809fb2aac8f X-Google-Attributes: gid103376,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!194.25.134.126.MISMATCH!newsfeed01.sul.t-online.de!t-online.de!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Mon, 29 Sep 2008 22:48:20 +0200 From: Georg Bauhaus Reply-To: rm.tsoh-bauhaus@maps.futureapps.de User-Agent: Thunderbird 2.0.0.17 (X11/20080925) MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Naming convention to identify functions with side effects References: <5654ee5f-aa9f-4fff-87e0-45854b850f26@y38g2000hsy.googlegroups.com> <29ac62e1-78da-4048-ad95-8f88a29f7d31@z6g2000pre.googlegroups.com> In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <48e13f14$0$6610$9b4e6d93@newsspool3.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 29 Sep 2008 22:48:20 CEST NNTP-Posting-Host: 7fc3cfdb.newsspool3.arcor-online.net X-Trace: DXC=7:GZ^f31d9:d8Nb@@ZG@b=McF=Q^Z^V384Fo<]lROoR18kFejV8USnVcf8i=<2Y]2NR<`WC05 X-Complaints-To: usenet-abuse@arcor.de Xref: g2news1.google.com comp.lang.ada:2144 Date: 2008-09-29T22:48:20+02:00 List-Id: Dmitry A. Kazakov wrote: > On Mon, 29 Sep 2008 11:55:49 -0700 (PDT), Adam Beneschan wrote: >> 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... > > I don't like either. Me neither. While a style of "packed programming" might be expected in SETL or APL, I can't imagine this sort of cleverness to be a preference when using a deliberately verbose language such as Ada. A more strict recommendation is perhaps worth noting, named the Command-query separation (coined by Betrand Meyer). For primitive functions of some type T (called queries, like Is_Loaded), it means the functions should not have abstract side effects. "Abstract side effects" are side effects that can change the return value of public functions of type T. (Functions are the only means to query the state of an object of type T.) Some issues become more obvious in a concurrent setting perhaps, Web_Page.Load ("http://www.irvine.com"); if Web_Page.Is_Loaded then... There needs to be a lock of some sort joining the two calls. Otherwise, the Web_Page object might have changed between the two calls, a logic error. Again, it might be tempting to pack the two calls in just one in order to hide the locking mechanism, to give the illusion of atomicity. But shouldn't normal Ada concurrency features be employed instead? If concurrency features of Ada are used instead, the naming problem is also gone: the commands (procedures) can be verbs and the queries (predicate functions) can be named "Is_Something" or "Has_Something".