comp.lang.ada
 help / color / mirror / Atom feed
From: "Dmitry A. Kazakov" <mailbox@dmitry-kazakov.de>
Subject: Re: Naming convention to identify functions with side effects
Date: Mon, 29 Sep 2008 21:52:18 +0200
Date: 2008-09-29T21:52:22+02:00	[thread overview]
Message-ID: <h9civa1o39f6$.79cdhcp3sfms$.dlg@40tude.net> (raw)
In-Reply-To: 29ac62e1-78da-4048-ad95-8f88a29f7d31@z6g2000pre.googlegroups.com

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



  reply	other threads:[~2008-09-29 19:52 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-09-29 18:17 Naming convention to identify functions with side effects Hibou57 (Yannick Duchêne)
2008-09-29 18:45 ` Hibou57 (Yannick Duchêne)
2008-09-29 18:55 ` Adam Beneschan
2008-09-29 19:52   ` Dmitry A. Kazakov [this message]
2008-09-29 20:48     ` Georg Bauhaus
2008-09-29 21:10       ` Adam Beneschan
2008-09-30 15:17         ` Georg Bauhaus
2008-09-30 17:40           ` Ray Blaak
2008-10-02 12:33       ` Ole-Hjalmar Kristensen
2008-10-03  9:18         ` Georg Bauhaus
2008-10-06  7:24           ` Ole-Hjalmar Kristensen
2008-10-03 11:51       ` Brian Drummond
2008-10-03 12:28         ` Dmitry A. Kazakov
2008-10-04 12:30           ` Marco
2008-10-04 13:05             ` (see below)
2008-10-04 15:14               ` Gary Scott
2008-10-11 11:32               ` Marco
2008-10-11 14:57                 ` Dmitry A. Kazakov
2008-10-11 16:05                 ` (see below)
2008-10-11 17:49                   ` Georg Bauhaus
2008-10-11 18:42                     ` (see below)
2008-10-03 13:15         ` Jeffrey Creem
2008-09-29 20:57 ` Georg Bauhaus
2008-09-29 22:22 ` Dr. Adrian Wrigley
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox