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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!newsfeed.freenet.de!news.tu-darmstadt.de!news.belwue.de!newsfeed.arcor.de!newsspool4.arcor-online.net!news.arcor.de.POSTED!not-for-mail Date: Tue, 30 Sep 2008 17:17:27 +0200 From: Georg Bauhaus User-Agent: Thunderbird 2.0.0.17 (Macintosh/20080914) 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> <48e13f14$0$6610$9b4e6d93@newsspool3.arcor-online.net> <2ed64106-52ef-4909-a0f0-ebb277856e8d@26g2000hsk.googlegroups.com> In-Reply-To: <2ed64106-52ef-4909-a0f0-ebb277856e8d@26g2000hsk.googlegroups.com> Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Message-ID: <48e24307$0$6583$9b4e6d93@newsspool4.arcor-online.net> Organization: Arcor NNTP-Posting-Date: 30 Sep 2008 17:17:27 CEST NNTP-Posting-Host: feb8b373.newsspool4.arcor-online.net X-Trace: DXC=9V4Z:nYc\BbOKO]LCQ@0g`4IUKfNfnc\616M64>jLh>_cHTX3jm;aET1Ci=a Adam Beneschan schrieb: > On Sep 29, 1:48 pm, Georg Bauhaus > wrote: > >> 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? > > This is a bit too esoteric for me. I think a much simpler reason for > the temptation to pack the two calls into just one is that it makes it > easier to stick the call into more complex Boolean expressions, e.g. > (assuming URL_Name's type is access string): > > if URL_Name /= null and then > Load_Web_Page (URL_Name.all) then ... > [stuff to do if we succeed] > else ... > [other stuff] > end if; This solution looks like a straight forward one at least in case of a single additional test in the conditional. However, as soon as the URL needs a little more inspection, 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; So, first, Load_Web_Page, which presumably has the important side effect of initializing some variable, looses the focus of attention. Then, sources of error may need to be distinguished since the errors are different in character (null pointer, syntax, and I/O). Load_Web_Page (I/O), being appended to the list of predicates and the null test, becomes one of many sources of potential failure in the same conditional. 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. So the distinct issues become blurred in this single conditional and the Boolean function Load_Web_Page does not significantly reduce verbosity. 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; (where URL_Name is of subtype "not null String_Ptr") Stupid obedience to command-query separation like in Is_Acceptable and Load_Web_Page might pay off in the end. Not that anyone cares.