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: 103376,1901f265c928a511 X-Google-Attributes: gid103376,public Path: controlnews3.google.com!news2.google.com!fu-berlin.de!uni-berlin.de!not-for-mail From: "Nick Roberts" Newsgroups: comp.lang.ada Subject: Re: Typing in Ada Date: Tue, 1 Jun 2004 00:22:27 +0100 Message-ID: <2i1t1lFij4g5U1@uni-berlin.de> References: X-Trace: news.uni-berlin.de mlZDmOx9W+ZoK5MAfrIN6wBXqMhK3jKBpRf8nq6IcKk0HCnE8= X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 Xref: controlnews3.google.com comp.lang.ada:964 Date: 2004-06-01T00:22:27+01:00 List-Id: "Peter C. Chapin" wrote in message news:Xns94FAA347BFEA8pchapinsovernet@207.106.93.237... > ... > This isn't an entirely fair comparison because in C, > ... > > I'm not sure if there is a formal definition of strong > typing or not. > ... Hehe. I'll think one would find, in practice, that most Ada programs tend to be far more strongly typed than C programs. That is to say that in most Ada programs it is typical to have constructions such as: type Apples is range 0..100; type Oranges is range 0..200; A: Apples; O: Oranges; whereas in typical C programs you either get: typedef int Apples; typedef int Oranges; Apples a; Oranges o; or more often than not simply: int a; int o; In either case, in Ada, the easy mistake: A := O; will be caught by the compiler, whereas in either of the C constructions: a = o; will not. I think this is the important point about 'strong' typing. It is one aspect of the basic principle that the more information you give the compiler, the more bugs it can catch for you. One more point. I encourage Ada programmers to use the style, where appropriate, of declaring the type of a literal by using a qualification. For example, suppose we know there is an 'Eat' procedure for Apples (but we are perhaps unsure whether Oranges has an 'Eat' or not). To eat ten apples, it would be prudent to write: Eat( Apples'(10) ); -- (1) rather than just: Eat( 10 ); -- (2) because if it so happens that there is an 'Eat' for Oranges, and it also so happens that the Eat for Apples has got hidden or commented out or whatever, the compiler would catch (1), but it would wrongly eat 10 oranges if we simply wrote (2). Of course, if boths Eats exist and are directly visible, the qualification would be one way to disambiguate the call. -- Nick Roberts