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-Thread: 103376,71fbc59f7794b9af X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news2.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!nx01.iad01.newshosting.com!newshosting.com!213.193.255.2.MISMATCH!feeder1.cambrium.nl!feed.tweaknews.nl!npeer.de.kpn-eurorings.net!newsfeed.arcor.de!news.arcor.de!not-for-mail From: "Dmitry A. Kazakov" Subject: Re: OO vs procedural 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: <1146771650.465144.99370@g10g2000cwb.googlegroups.com> <87u085v8vi.fsf@ludovic-brenta.org> Date: Fri, 5 May 2006 09:58:29 +0200 Message-ID: NNTP-Posting-Date: 05 May 2006 09:55:03 MEST NNTP-Posting-Host: 86393e0e.newsread4.arcor-online.net X-Trace: DXC=cCAgDT:4Ybna0B5i45NL;d:ejgIfPPlddjW\KbG]kaMh]kI_X=5KeafLjGF=S\KbWi[6LHn;2LCVn7enW;^6ZC`dIXm65S@:3>o X-Complaints-To: usenet-abuse@arcor.de Xref: g2news2.google.com comp.lang.ada:4086 Date: 2006-05-05T09:55:03+02:00 List-Id: On Thu, 04 May 2006 22:21:37 +0200, Ludovic Brenta wrote: > "kevin cline" writes: >> In the second paper, they give this example: >> >> The authors then point out a describe a potential pitfall of this code >> -- that a derived type implementation may fail to call the base >> implementation. This is true. The authors fail to point out that this >> possibility could have been prevented by correct base class design. >> >> I also fail to understand why this error is hard to test, but perhaps I >> do not understand S3 testing methods. I would have expected that a >> failure of a derived type X_Alert to call the base type Handle method >> would have been caught by a unit test of X_Alert, when it was observed >> that after calling X_Alert.Handle, no logging occured. >> >> I would also expect that the error would be easily detected through any >> formal verification process, since the erroneous Handle method would >> not meet the 'Logging occured' postcondition. > > Of course, what you say is true - good unit testing or good peer > review will catch the error, and the formal verification process will > document how the error was found, corrected, and verified to be > corrected. But, by that argument, "any good programmer with a good > process can write perfect software in any language, even assembly > language". No, I don't think that was the point. I agree with Kevin. IMO the designs the author presented are obviously not equivalent. So the paper is quite misleading in that respect. More detailed: SP version goes: procedure Handle (A: Alert) is begin CH; -- Code common to all alerts Log (A); -- alerts are logged here case A.Device is when Flaps => FH; -- Flaps specific handling when Rudder => RH; -- Rudder specific handling end case; end Handle; As an OO equivalent he presents Handle declared as a primitive procedure. This is *not* an equivalent design pattern. An equivalent one would be to use a class-wide Handle dispatching to device-specific handling: procedure Handle (A: Alert'Class) is -- Class-wide begin CH; -- Code common to all alerts Log (A); -- alerts are logged here Do_Specific (A);-- Specific handling end Handle; procedure Do_Specific (A : Flaps_Alert); -- Primitive procedure Do_Specific (A : Rudder_Alert); Now, Log is perfectly enforced as in SP version. (*) The fallacy is that the problem of "extensible subprograms" is not specific to OO. It is to Ada design. Furthermore, structured programming does not respond this problem either. ----------- * BTW, author is silent about what would happen if some idiot called Log from FH path. Observe, that Ada's OO design provides an additional *safety* here: no implicit redispatch allowed. So if Log were declared class-wide (as it should), then Ada compiler wouldn't let our idiot to call it from Do_Specific, without an explicit type conversion! -- Regards, Dmitry A. Kazakov http://www.dmitry-kazakov.de