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-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news1.google.com!news3.google.com!feeder1-2.proxad.net!proxad.net!feeder2-2.proxad.net!newsfeed.arcor.de!newsspool2.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> <48e13f14$0$6610$9b4e6d93@newsspool3.arcor-online.net> Date: Fri, 3 Oct 2008 14:28:47 +0200 Message-ID: NNTP-Posting-Date: 03 Oct 2008 14:28:48 CEST NNTP-Posting-Host: 5a1119ec.newsspool2.arcor-online.net X-Trace: DXC=jFlo`jP;64=TQL:hoD@>T?A9EHlD;3Yc24Fo<]lROoR14nDHegD_]R5AiPCkoWY3Q5DNcfSJ;bb[5IRnRBaCd__ZO0P0FGQ< On Fri, 03 Oct 2008 12:51:33 +0100, Brian Drummond wrote: > 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. Side-effects are bad in any subprograms, be them functions or procedures. When the effect of the operation Load is solely the state of Web_Page then you should be able to spell it as: Web_Page.Load ("http://www.irvine.com"); if Web_Page.Loaded then... > (The web page may indeed change, but "Loaded" refers to the version > extant during the .Load call) What is the use of this test if it does not reflect the state of Web_Page? > 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? Yes. In this design the effect of Load is the tuple (Web_Page, Loaded). It is considerably more difficult for the reader to understand how the effect is distributed among the tuple members, and when and if their separate states are consistent to the state of what this tuple is supposed to model. According to OO design principles we should bundle such things into one object, Web_Page for example. Then the operation "test if true" of Boolean Loaded would become function Loaded of Web_Page. But even so the code Web_Page.Load ("http://www.irvine.com"); if Web_Page.Loaded then... looks suspicious to me. Web_Page must fulfill its contract regardless of outcome of Load. When "not loaded" is a valid state of Web_Page then there is no obvious reason why anybody would need to test for it. Say the operation Render should then be able to render a not loaded page. Like firefox does. Otherwise, if no page may be not loaded, then the constructor of Web_Page is responsible to initialize a page properly and Load, if any, should raise an exception rather than silently leaving the page in an invalid state. -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de