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: fdb77,5f529c91be2ac930 X-Google-Attributes: gidfdb77,public X-Google-Thread: 1108a1,59ec73856b699922 X-Google-Attributes: gid1108a1,public X-Google-Thread: 103376,583275b6950bf4e6 X-Google-Attributes: gid103376,public X-Google-Thread: f43e6,899fc98b2883af4a X-Google-Attributes: gidf43e6,public X-Google-ArrivalTime: 2003-05-18 18:37:33 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!wn14feed!worldnet.att.net!bgtnsc04-news.ops.worldnet.att.net.POSTED!not-for-mail Reply-To: "James S. Rogers" From: "James S. Rogers" Newsgroups: comp.lang.java.advocacy,comp.object,comp.lang.ada,comp.software-eng 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> Subject: Re: Logic Errors and Ada (Was: A big hairy thread on Ada, Quality, and Drivers) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1158 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1165 Message-ID: Date: Mon, 19 May 2003 01:37:32 GMT NNTP-Posting-Host: 12.86.34.160 X-Complaints-To: abuse@worldnet.att.net X-Trace: bgtnsc04-news.ops.worldnet.att.net 1053308252 12.86.34.160 (Mon, 19 May 2003 01:37:32 GMT) NNTP-Posting-Date: Mon, 19 May 2003 01:37:32 GMT Organization: AT&T Worldnet Xref: archiver1.google.com comp.lang.java.advocacy:64130 comp.object:63659 comp.lang.ada:37492 comp.software-eng:19282 Date: 2003-05-19T01:37:32+00:00 List-Id: "soft-eng" wrote in message news:9fa75d42.0305181502.53703035@posting.google.com... > 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 This is the common level of discipline in Ada programming. The reason it has become common is that the benefits provided by these distinct types far exceed the effort required to create them. > will be just real numbers (floats), whatever the language chosen. So > academically this is an advantage, in practice it won't be there. > (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...) Ada user defined numeric types are more than simply the different sized ints and floating point types in C and C++. C and C++ give you no easy way to define a type that truly fits the problem. For instance, if you are monitoring voltages that must always be between -5.0 and +5.0 volts, you can define the following type: type Voltages is digits 15 range -5.0..5.0; This defines a floating point type with a 15 decimal digits of precision and a valid range of values from -5.0 through 5.0. Any attempt to evaluate a value outside that range will result in a Constraint_Error exception being raised. Note that the C and C++ numeric types like int8, int16, uint32, provide much less help in matching your needs in this case. Similarly, float and double do not help in ensuring that the data is correctly within range. Neither to they ensure 15 decimal digits of precision. > > 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. Yes, C++ does allow you to create such classes. Upon creating those classes you also need to define all the appropriate numeric operators for the class, as well as the logic for restricting the valid values to a domaine-valid range. This takes a LOT more discipline and time than achieving the same thing in Ada. The Voltages type defined above gets all the floating point operators defined for it automatically by the compiler. It also gets all the range checking defined automatically by the compiler. The Ada solution does take a bit more discipline than simply using the predefined float or long_float types. The difference in the source code is minimal. The real discipline comes in designing data types to satisfy the requirements of your problem domaine. It takes some work and some thought. This is the same level of work and thought that is needed in any language to produce a reliable, safe, efficient design. Ada also makes safe I/O for user defined numeric types safe and easy. The standard generic package Ada.Text_IO.Float_IO may be instantiated for any floating point type. package Voltage_IO is new Ada.Text_IO.Float_IO(Voltages); The I/O routines in that instantiation will validate data entry over the allowed range of values for type Voltages. Any attempt to enter an out-of-range value will result in the Constraint_Error exception being raised. All you need to do is write the appropriate exception handlers for your application. Not only is this kind of discipline common in most Ada programming teams, many teams set up coding guidelines prohibiting the use of the pre-defined data types. For junior Ada programmers this approach causes problems. They find the compiler keeps complaining about improper mixing of types. Even the junior Ada programmers find, however, that once the program compiles it has far fewer logic errors caused by inappropriate mixing of variables in a calculation. This saves much more time in debugging than was consumed in compilation. Senior Ada programmers seldom encounter such a difficulty during compilation. They are used to the discipline needed to avoid most compilation diagnostic messages. Jim Rogers