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,XPRIO 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: "Robert C. Leif, Ph.D." Subject: RE: Help me to chose between ADA 95 and C++ Date: 1999/12/14 Message-ID: #1/1 X-Deja-AN: 560788140 Content-Transfer-Encoding: 7bit To: X-Priority: 3 (Normal) Content-Type: text/plain; charset="iso-8859-1" X-MimeOLE: Produced By Microsoft MimeOLE V5.00.2919.6600 X-Complaints-To: usenet@enst.fr Importance: Normal X-Trace: menuisier.enst.fr 945222330 233 137.194.161.2 (15 Dec 1999 01:45:30 GMT) Organization: ENST, France X-BeenThere: comp.lang.ada@ada.eu.org X-MSMail-Priority: Normal Mime-Version: 1.0 Reply-To: comp.lang.ada@ada.eu.org NNTP-Posting-Date: 15 Dec 1999 01:45:30 GMT Newsgroups: comp.lang.ada Date: 1999-12-15T01:45:30+00:00 List-Id: From: Bob Leif To: Richard Riehle et al. How do you set an instantiation equal to a universal integer or universal_real? I tried to do this with a 32 bit data type and had to define a non_private type for simple operations like Data_32 : Data_32_Type := 7; I then converted from the non_private to the private (Ugly). -----Original Message----- From: Richard D Riehle [mailto:laoXhai@ix.netcom.com] Sent: Tuesday, December 14, 1999 10:55 AM To: comp.lang.ada@ada.eu.org Subject: Re: Help me to chose between ADA 95 and C++ 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.