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!feeder.news-service.com!news.astraweb.com!newsrouter-eu.astraweb.com!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool3.arcor-online.net!news.arcor.de.POSTED!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: Naming convention to identify functions with side effects Newsgroups: comp.lang.ada User-Agent: 40tude_Dialog/2.0.15.1 MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Reply-To: mailbox@dmitry-kazakov.de Organization: cbb software GmbH References: <5654ee5f-aa9f-4fff-87e0-45854b850f26@y38g2000hsy.googlegroups.com> <29ac62e1-78da-4048-ad95-8f88a29f7d31@z6g2000pre.googlegroups.com> Date: Mon, 29 Sep 2008 21:52:18 +0200 Message-ID: NNTP-Posting-Date: 29 Sep 2008 21:52:22 CEST NNTP-Posting-Host: b251d7cd.newsspool2.arcor-online.net X-Trace: DXC=RI]cZ3EH0 On Mon, 29 Sep 2008 11:55:49 -0700 (PDT), Adam Beneschan wrote: > 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... I don't like either. They hide the side-effect instead of publishing it. Is_Loaded is a property of a page, it is not of an URL. To me it should be: type Web_Page is ...; function Load (URL : String) return Web_Page; function Is_Loaded (Page : Web_Page) return Boolean; Should pages be cached, then the cache of pages must be exposed: type Web_Page is ...; type Web_Pages_Cache is ...; procedure Load (Cache : in out Pages_Cache; URL : String); function Is_Loaded (Cache : Pages_Cache; URL : String) return Boolean; function Get_Loaded (Cache : Pages_Cache; URL : String) return Web_Page; -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de