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.8 required=5.0 tests=BAYES_00,INVALID_DATE autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b19fa62fdce575f9 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 1994-12-01 13:40:34 PST Path: bga.com!news.sprintlink.net!howland.reston.ans.net!swrinde!ihnp4.ucsd.edu!network.ucsd.edu!mbk From: mbk@inls1.ucsd.edu (Matt Kennel) Newsgroups: comp.lang.ada Subject: Re: Why don't large companies use Ada? Followup-To: comp.lang.ada Date: 1 Dec 1994 20:35:08 GMT Organization: Institute For Nonlinear Science, UCSD Message-ID: <3blc1s$8gr@network.ucsd.edu> References: <3bj07h$qus@felix.seas.gwu.edu> NNTP-Posting-Host: lyapunov.ucsd.edu X-Newsreader: TIN [version 1.1 PL8] Date: 1994-12-01T20:35:08+00:00 List-Id: Michael Feldman (mfeldman@seas.gwu.edu) wrote: : >How about "Ada - use it when you want to multiply a length by a length : >and get a length, or when you want to be prevented from dividing an area : >by a length because they have different types." : This is NOT my favorite aspect of the Ada type system, and I seriously : wish the language directly supported dimensions. As it is, I try to : avoid using derived numeric types, preferring to stick to subtypes : (subrange types) which give me the necessary range checking but don't : get in the way otherwise. : >(PS: yes, you can fix that by defining zillions of additional *,/,- and + : >functions, but good grief...) : Well, there are also other solutions. One such is to use a variant : record with 3 tags for the physical dimensions. This makes up into : a very simple package and is bulletproof in the sense that mangled : dimension-analysis will get caught either at compile time or (at worst) : at run time with a nicely raised exception. Does these include lepton number? Charge? :-) Atomic concentrations? Temperature? (Do you keep that separate or consider it as energy units through boltzmann's constant? Usually that's wrong, but sometimes right?) Units of electric field? What system of lengths/time/masses? : My CS2-level students : use and modify this package in their class projects. : It does require a bit of runtime overhead, i.e. space for the tags : and a bit of runtime checking, and I agree that it would be : preferable to do this at compile time. But variant records are : done so type-safely in Ada that this very simple solution works well. I think it's a nice student project, but in real physical computations, the right way is often to go into a system of units that is natural for your problem, and work with these nondimensional variables. You usually gain more insight into the important terms in your computations and you don't end up with insanely small or insanely large exponents (no overflow) unless things are physically negligable or dominant. cheers matt : Mike Feldman -- -Matt Kennel mbk@inls1.ucsd.edu -Institute for Nonlinear Science, University of California, San Diego -*** AD: Archive for nonlinear dynamics papers & programs: FTP to -*** lyapunov.ucsd.edu, username "anonymous".