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 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: f43e6,899fc98b2883af4a X-Google-Attributes: gidf43e6,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-Thread: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-ArrivalTime: 2003-05-18 19:01:05 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news.uchicago.edu!newsswitch.lcs.mit.edu!newsfeed.mathworks.com.MISMATCH!newsfeed!wn13feed!wn12feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi_feed4!attbi.com!sccrnsc02.POSTED!not-for-mail Message-ID: <3EC83ABB.60702@attbi.com> From: "Robert I. Eachus" User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.0.2) Gecko/20021120 Netscape/7.01 X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: comp.lang.java.advocacy,comp.object,comp.lang.ada,comp.software-eng Subject: Re: Logic Errors and Ada (Was: A big hairy thread on Ada, Quality, and Drivers) References: <9fa75d42.0304230424.10612b1a@posting.google.com> <9fa75d42.0305130543.60381450@posting.google.com> <254c16a.0305140549.3a87281b@posting.google.com> <9fa75d42.0305141747.5680c577@posting.google.com> <1053027582.984315@master.nyc.kbcfp.com> <3ec4b5c5$1@news.wineasy.se> <254c16a.0305160930.40bb42f9@posting.google.com> <9fa75d42.0305181502.53703035@posting.google.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 24.62.164.137 X-Complaints-To: abuse@attbi.com X-Trace: sccrnsc02 1053309657 24.62.164.137 (Mon, 19 May 2003 02:00:57 GMT) NNTP-Posting-Date: Mon, 19 May 2003 02:00:57 GMT Organization: AT&T Broadband Date: Mon, 19 May 2003 02:00:58 GMT Xref: archiver1.google.com comp.lang.java.advocacy:64134 comp.object:63661 comp.lang.ada:37494 comp.software-eng:19284 Date: 2003-05-19T02:00:58+00:00 List-Id: soft-eng wrote: > That sounds to me an unrealistic level of discipline: subtyping > to the extent that all lattitudes and longitudes (and things > along that line) are separate types. More common usage is that both > will be just real numbers (floats), whatever the language chosen. So > academically this is an advantage, in practice it won't be there. You still refuse to "get it." If I want to declare Latitude as its own floating-point type in Ada I would say: type Latitude is digits 7 range -90.0..90.0; In actual practice I would be more likely to declare it to be a fixed-point type with a declaration like: type Latitude is digits 8 delta 0.000001 range -90.0..90.0; or if I wanted to represent hundreths of a second exactly: type Latitude is delta 1.0/360000 range -90.0..90.0; for Latitude'Small use 1.0/360000; However, if I wanted to make it a subtype of Float for some reason, I would say: subtype Latitude is new Float range -90.0..90.0; For longitude you need a larger range: type Longitude is digits 7 range -180.0..180.0; -- or type Longitude is digits 9 delta 0.000001 range -180.0..180.0; -- or type Longitude is delta 1.0/360000 range -180.0..180.0; for Longitude'Small use 1.0/360000; -- or subtype Longitude is new Float range -180.0..180.0; Now the smallest of these in number of characters is defining a new floating point type. So if you laboriously type using hunt and peck, that might influence you to use the new floating point type. I assure you that the fact that it takes 15 more characters than using a floating point type has nothing to do with my preference for the decimal version. I would use whatever approach is most appropriate for the problem. But it wouldn't occur to me to make Latitude and Longitude subtypes of Float. > (Similarly, as other messages point out, in practice, any usage of > subranges you will see in Ada is just what you have in C++, > int8, int16, int32. Though in a classroom setting it may sound like > a great advantage to be able to have my own subranges of integers > from 1 to 9102 each and every time I need it...) I will say it one last time. NO YOU WON'T. You are much more likely to see programmers new to Ada using predefined types all over the place before they finally "get it." And start using programmer defined types because they are easier and better. There is zero benefit to using predefined types in Ada for much other than indexes of strings, SOME loop counters, and some other arrays. It would defeat the whole purpose of having all these safety features if they were too costly to use, in either programmer's time or in program execution time. Using the safety features in Ada saves both, even if you never actually need that safety for some particular type. If in Ada I am iterating over some array Foo, I could go look up the type declaration for Foo, find what its range was, and the type of that range, and then write some code that will be error prone if the declaration of Foo is ever changed. Or I can write: for I in Foo'Range loop ... end loop; or if for some reason I need to go backwards: for I in reverse Foo'Range loop ... end loop; I don't have to think about what that range is, whether it is static or dynamic, or whether it is an 8-bit integer, a 32-bit integer, a character type, or the colors of the rainbow. As long as I use Foo(I) to reference elements of Foo, not only do I know they are safe, but the compiler does too. So no range checking is needed at run-time and I still get that safety. > But in any case, you sure can create Lattitude and Longitude classes > in C++ as well if you are so disciplined, so the advantage you are > pointing out is not very clear. There are no such programmers. All programmers are human, at least so far, and they have a limited capacity to juggle things in their head. Adding Lattitude and Longitude classes in C++ will increase the number of things that a programmer has to work with, so they reduce the complexity of problem that the programmer can easily handle. In Ada, once I declare Latitude and Longitude, I can forget all the details. All I have to remember is that there are two types with those names, and the compiler will let me know if I ever make a mistake trying to assign a Latitude value to a Longitude object, or vice-versa. You will notice that I could make a mistake if I assigned the aggregate: (23.347,45.103) to an object with Lattitude and Longitude fields. The right thing to do is write: (Lattitude'(23.347), Longitude'(45.103)) but I will admit that there are programmers who will be that lazy. Of course the system designers can fight back by making the Lattitude and Longitude types private so that they don't have literals visible to users of the type. But that is a different discussion.