From: Jeffrey Creem <jeff@thecreems.com>
Subject: Re: Naming convention to identify functions with side effects
Date: Fri, 03 Oct 2008 13:15:01 GMT
Date: 2008-10-03T13:15:01+00:00 [thread overview]
Message-ID: <0nghr5-dfc.ln1@newserver.thecreems.com> (raw)
In-Reply-To: <fd0ce4ptnhuoo78ecu4em6op8nv5hnj338@4ax.com>
Brian Drummond wrote:
> On Mon, 29 Sep 2008 22:48:20 +0200, Georg Bauhaus
> <see.reply.to@maps.futureapps.de> wrote:
>
>> Dmitry A. Kazakov wrote:
>>> On Mon, 29 Sep 2008 11:55:49 -0700 (PDT), Adam Beneschan wrote:
>>>> if Web_Page_Is_Loaded ("http://www.irvine.com") then...
>>>> if Load_Web_Page ("http://www.irvine.com") then...
>>> I don't like either.
>> Me neither.
>>
>> 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.
>
> As someone relatively new to Ada, I have to ask, is there need for
> anything more sophisticated than
>
> Web_Page.Load ("http://www.irvine.com", Loaded);
> if Loaded then...
>
> which avoids side effects in functions, preserves the atomicity of the
> operation and test, but allows the test result to be used later.
> (The web page may indeed change, but "Loaded" refers to the version
> extant during the .Load call)
>
> Its intent and operation are quite clear, and it's a common paradigm in
> other languages.
>
> Beyond being a little untidy, is there any reason for avoiding it?
>
> - Brian
>
Perfectly valid paradigm in an Ada program as well. The risk of a style
like this is the traditional sloppy programming risk where one may just
ignore Loaded and continue processing down the happy path. In some
cases, this may mean that using an exception would have been a better
choice. In other cases, this sort of a Loaded status would be fine. In
most cases, getting too worked up about the micro-style issues between
the exception and the status is a small issue compared to the
architectural mess that people in general make of their code.
Static analyzers and in many cases some compilers are pretty good about
warning on cases where Loaded was written to but not read which can help
manage the risk of sloppy programming.
next prev parent reply other threads:[~2008-10-03 13:15 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
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 [this message]
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