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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,6b6619eb9cada212 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: Help me to chose between ADA 95 and C++ Date: 1999/12/14 Message-ID: <8363hv$6cu$1@nntp9.atl.mindspring.net>#1/1 X-Deja-AN: 560634861 References: <01bf37fb$a91afb60$0564a8c0@IS-D2D04C.test> <829rbv$a8m$1@nntp6.atl.mindspring.net> <01bf3e32$0b9dc880$022a6282@dieppe> <385112AE.7E2CFA9@rdel.co.uk> <833d8i$sjf$1@nntp5.atl.mindspring.net> <38566835.B4A2D48@rdel.co.uk> Organization: MindSpring Enterprises X-Server-Date: 14 Dec 1999 18:50:39 GMT Newsgroups: comp.lang.ada Date: 1999-12-14T18:50:39+00:00 List-Id: In article <38566835.B4A2D48@rdel.co.uk>, Chris Powell wrote: >Good type design (especially in an OO system) would define types with >appropriate functions acting on those types, possibly returning other >types effectively defining allowed conversions. This is no different >from defining C++ classes with appropriate methods which are effectively >type safe through data hiding and a well defined public interface. I am going to respond to only one of your points. Your response to my other arguments was intelligent and thoughtful. In the case of this response, you are right on the mark! I have long felt that we often expose too much of some numeric types in our packages and ought to take more care to hide some of the details. This would lead to better maintenance as well as more options for "design by contract." The following example will be short, and that is always a problem since code fragments never fully represent the range of possibilities. package Real_Number is type Real is private; function "+" (L, R : Real) return Real; -- same for all other operators Divide_By_Zero : exception; -- more exceptions private type Real is digits 9; end Real_Number; The corresponding package body can have additional checks within each operation to ensure conformity to the application constraints. It turns out, though, that implementing this, in Ada, is somewhat tedious because of the need to avoid recursive calls within each function in the package body. It can be done. More interesting is, generic type Number is private; with function "+" (L, R : Number) return Number is <>; -- all other operators similarly declared as generic parameters package Generic_Operators is end Generic_Operators; with Generic_Operators; generic with package Operators is new Generic_Operators (<>); package Statistics is ... end Statistics; which allows instantiation with any numeric type. Also, there is a way to instantiate this with a non-numeric type that I published in an Ada Letters a couple of years ago. So, on this point, Chris, I am pretty much in agreement with you. Richard Riehle P.S. I apologize if my earlier reply was a bit to harsh.