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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 109fba,1042f393323e22da X-Google-Attributes: gid109fba,public X-Google-Thread: 1014db,1042f393323e22da X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,1042f393323e22da X-Google-Attributes: gid103376,public From: kaz@vision.crest.nt.com (Kaz Kylheku) Subject: Re: Any research putting c above ada? Date: 1997/04/14 Message-ID: <5itkgg$lp@bcrkh13.bnr.ca>#1/1 X-Deja-AN: 234784030 References: <5ih6i9$oct$1@waldorf.csc.calpoly.edu> <2senchydgk.fsf@hpodid2.eurocontrol.fr> <5im3an$3dv@bcrkh13.bnr.ca> <2sybamvslk.fsf@hpodid2.eurocontrol.fr> Organization: Prism Systems Inc. Newsgroups: comp.lang.c++,comp.lang.c,comp.lang.ada Date: 1997-04-14T00:00:00+00:00 List-Id: In article <2sybamvslk.fsf@hpodid2.eurocontrol.fr>, Steve Jones - JON wrote: >kaz@vision.crest.nt.com (Kaz Kylheku) writes: >> >In Ada you can restrict the user from assigning between incompatible types, >> >you can data hide etc etc. >> >> This is true of C as well. Assigning between incompatible types is a constraint >> violation which *requires* a diagnostic. It's all in ISO 9899:1990. > >A Diagnostic yes, but Ada prevents you from doing it. And this is only >on weak types anyway. That's a pointless distinction. If you see diagnostics, fix the program. It's trivial to make a modified compiler in which any diagnostic is treated as an error which results in a terminated translation. For example, the GCC -Werror flag: ``Treat warnings as errors; abort compilation after any warning''. True, not all compilers have such an option. But a good engineer doesn't need it. Any decent engineer will fix the program if it produces diagnostics. We are talking about good engineers aren't we? If we are talking about run of the mill goofballs, language won't help. As someone said earlier, Ada is a tool for software engineers. It's use won't turn you into one, however. To me, it's good enough _that_ a compiler or checker catches the error. Whether or not it will try to emit a translation in spite of the diagnostic is immaterial, because I'm not interested in such a translation. I anticipate a good counterargument here: that you sometimes have to maintain code written by goofs who ignore diagnostics (and even operate the tools with minimum diagnostic levels). It's hard to go back and fix a body code which incorporates undefined behavior into its very design. Some people just don't deserve the freedom to ignore compiler diagnostics! >The Ada code would be >-- Units in hundreds of feet. >type Cleared_Flight_Level_Type is new integer range -10 .. 1000; > >-- Units in Knots, Higher values calculated as Mach. >type Airspeed_Type is new Integer range 0 .. 700; > >Airspeed : Airspeed_Type := 4; -- 4 is a literal constant of type Airspeed_Type > >Cleared_Flight_Level : Cleared_Flight_Level_Type := Airspeed; > >This will bomb out in the compiler as the two types are difference. The >literal 4 is inherited from the parent type into the new types (as are the >operators +, - etc). This could be seen as a safety violation. A truly strongly typed language would require you to coerce all such literals into an appropriate type, and would not inherit things behind your back. Ada is clearly not as perfect as the proponents would have us believe. It can be seen as a weakness that '4' can, like a chameleon, be an Airspeed hither and a Cleared_Flight_Level type tither. Like C, Ada sacrifices safety for the sake of programmer convenience, though arguably to a lesser extent.