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 X-Google-Thread: 103376,cc4f25d878383cc X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-05 20:15:01 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!netnews.com!xfer02.netnews.com!newsfeed2.earthlink.net!newsfeed.earthlink.net!news.mindspring.net!not-for-mail From: Richard Riehle Newsgroups: comp.lang.ada Subject: Re: Another Idea for Ada 20XX Date: Wed, 05 Dec 2001 20:14:24 -0800 Organization: AdaWorks Software Engineering Message-ID: <3C0EF0A0.9F42EDB4@adaworks.com> References: <3C0AACCE.329CFB60@worldnet.att.net> <45601fc.0112031740.3e217c8a@posting.google.com> <3C0CF4E3.A53D20A7@sparc01.ftw.rsc.raytheon.com> Reply-To: richard@adaworks.com NNTP-Posting-Host: 9e.fc.cd.2a Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Server-Date: 6 Dec 2001 04:15:50 GMT X-Mailer: Mozilla 4.7 [en] (Win98; I) X-Accept-Language: en Xref: archiver1.google.com comp.lang.ada:17496 Date: 2001-12-06T04:15:50+00:00 List-Id: Wes Groleau wrote: > Larry Kilgallen wrote: > > If they simply used common type declarations, a lot of errors would > > be detected. If Meters is a new type and is used throughout, and > > Feet is another new type, it becomes difficult to add them. > > But that's not enough to prevent 2 Meters * 2 Meters = 4 Meters > nor to allow 10 minutes * 5 KPH = 833 Meters > > -- > Wes Groleau > http://freepages.rootsweb.com/~wgroleau Correct. However, a simple type declaration is just part of the solution. I don't believe it requires a change to the language. Rather, it begs for a simple object-oriented programming solution, along with some old-fashioned encapsulation. package Metric_Number is type Metric_Type is private; -- export services for arithmetic on this type function "+"(L, R : Metric_Type) return Metric_Type; -- more arithmetic and boolean functions private -- full definition for the Metric_Type; -- helper type to avoid recursion during implementation end Metric_Number; In this way, we can control the behavior of each function with some exactness instead of depending only on the predefined behavior of ALRM Chapter 4 for numeric types. Of course, if we also had pre- and post-conditions as part of the language, this contract could be made even more robust. In that case, there would definitely be no need for a specialized language feature. Richard Riehle