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.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,3885b7fd66a1db28 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2003-01-09 19:26:14 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!lnsnews.lns.cornell.edu!newsstand.cit.cornell.edu!ngpeer.news.aol.com!uunet!dca.uu.net!ash.uu.net!spool0901.news.uu.net!spool0900.news.uu.net!reader0902.news.uu.net!not-for-mail Date: Thu, 09 Jan 2003 22:26:12 -0500 From: Hyman Rosen User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3a) Gecko/20021212 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.ada Subject: Re: Why is Ada NOT a good choice for a beginner to programming? References: <8ivo1vo5ir3piqsck4ondj0cuo47g426kf@4ax.com> <9gMS9.483613$GR5.189928@rwcrnsc51.ops.asp.att.net> In-Reply-To: Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit Organization: KBC Financial Products Message-ID: <1042169172.955986@master.nyc.kbcfp.com> Cache-Post-Path: master.nyc.kbcfp.com!unknown@nightcrawler.nyc.kbcfp.com X-Cache: nntpcache 3.0.1 (see http://www.nntpcache.org/) NNTP-Posting-Host: 204.253.250.10 X-Trace: 1042169173 reader2.ash.ops.us.uu.net 29439 204.253.250.10 Xref: archiver1.google.com comp.lang.ada:32852 Date: 2003-01-09T22:26:12-05:00 List-Id: Georg Bauhaus wrote: > In which languages has this been fixed? In C++. It's easy to define classes which are nothing more than a wrapper around an underlying numeric type, are the same size as that type, but which also carry around unit information, so that the product of two lengths is an area. It looks something like this: template struct Unit { T v; Unit(T v) : v(v) { } // Addition and subtraction are defined only for identical units Unit operator+(Unit o) { return Unit(v + o.v); } Unit operator-(Unit o) { return Unit(v - o.v); } }; // Multiplication and division are defined for any units template inline Unit operator*(Unit l, Unit r) { return Unit(l.v * t.v); } template inline Unit operator/(Unit l, Unit r) { return Unit(l.v / t.v); } typedef Unit Length; typedef Unit Area; Area compute(Length l, Length r) { return l * r; }