comp.lang.ada
 help / color / mirror / Atom feed
From: Ray Blaak <rAYblaaK@STRIPCAPStelus.net>
Subject: Re: Naming convention to identify functions with side effects
Date: Tue, 30 Sep 2008 17:40:48 GMT
Date: 2008-09-30T17:40:48+00:00	[thread overview]
Message-ID: <ud4ilh6qx.fsf@STRIPCAPStelus.net> (raw)
In-Reply-To: 48e24307$0$6583$9b4e6d93@newsspool4.arcor-online.net

Georg Bauhaus <rm.dash-bauhaus@futureapps.de> writes:
> I need more predicates. Since these are called before Load_Web_Page
> is called, Load_Web_Page is "pushed down" the conditional chain,
> hiding it and also blurring the distinct sources of error:
> 
>    if URL_Name /= null and then
>       Valid_Protocol (URL_Name.all) and then
>       Host_Allowed (URL_Name.all) and then
>       No_Up_Directories (URL_Name.all) and then
>       Load_Web_Page (URL_Name.all)
>    then ...
>       [stuff to do if all test succeed and the page was finally loaded]
>    else ...
>       [something has failed, maybe loading has failed, do other stuff]
>    end if;
[...]
> Finally, the programmer wanting to reduce verbosity by
> making Load_Web_Page a Boolean function now causes
> verbosity by chaining the many predicates.
> This amount by far exceeds the intended reduction in verbosity
> and renders the original intent (of saving words) mostly
> fruitless.
[...]
> At this point I remember advice from The Little Schemer
> to use little helper functions (that can be nested if
> needed). Thus,
> 
>    if Is_Acceptable (URL_Name.all) then
>       Load_Web_Page (URL_Name.all, Data);
>       Construct (Data, Result);
>    else
>       raise Syntax_Error;
>    end if;

Or, you could make Load_Web_Page only work if a page is valid:

    if Load_Web_Page (URL_Name.all, Data) then
       Construct (Data, Result);
    else
       raise Syntax_Error;
    end if;

Or, my favourite, make Load_Web_Page be a procedure that wants only valid
pages and have *it* throw any errors as needed:

       Load_Web_Page (URL_Name.all, Data); -- raises Syntax_Error if bad
       Construct (Data, Result);

-- 
Cheers,                                        The Rhythm is around me,
                                               The Rhythm has control.
Ray Blaak                                      The Rhythm is inside me,
rAYblaaK@STRIPCAPStelus.net                    The Rhythm has my soul.



  reply	other threads:[~2008-09-30 17:40 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
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 [this message]
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