Xref: utzoo comp.lang.c:26856 comp.lang.misc:4430 Path: utzoo!attcan!uunet!crdgw1!jupiter!rimvallm From: rimvallm@jupiter.crd.ge.com (Magnus Rimvall) Newsgroups: comp.lang.c,comp.lang.misc Subject: Re: C strongly typed? Message-ID: <6016@crdgw1.crd.ge.com> Date: 13 Mar 90 16:59:04 GMT References: <259@eiffel.UUCP) <1990Mar1.172526.28683@utzoo.uucp) <849@enea.se) <1990Mar7.182230.5517@utzoo.uucp) <862@enea.se> <39941@ism780c.isc.com> Sender: news@crdgw1.crd.ge.com Followup-To: comp.lang.c Organization: General Electric Corporate R&D Center Lines: 38 In article <39941@ism780c.isc.com> marv@ism780.UUCP (Marvin Rubenstein) writes: >I am unaware of any commonly available language that prevents this form of >mistake. Look at the following: > > double distance; > double time; > double velocity; > > velocity = distance/time; /* this makes sense */ > velocity = distance+time; /* I mixed 'apples' and 'oranges' and produced > a lemon :-) */ > >I did read a paper (sorry, I don't have the reference) describing a language >that allowed one to augment the the type declaration with a units declaration >so as to be able to catch errors of this form. > > Marv Rubinstein The problem with mismatching units is particularly bothersome in the area of continuous system simulation, where the whole program/model consists of equations taking units. Some simulation programs do indeed support unit checking (a new version of the simulation language CSSL-IV which supported unit declarations/checks was announced some time ago - this might have been the paper Marv read). The task of unit tests is, at least in the USA, only half the battle. Until the metric system is adopted, we would also need automatic scaling of units (even the *dumbest* unit test unit could learn that a KW is equal to 1000 W, without knowing what a W itself is. Not even intelligent human beings can know for sure how much a "ton" or a "gallon" really is ... but this does not really belong in comp.*, so flame me in sci.misc). Magnus Rimvall Disclaimer: This letter does not necessarily reflect the opinions of anybody else (though they should)