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: 10d15b,d730ea9d54f7e063 X-Google-Attributes: gid10d15b,public X-Google-Thread: 1014db,dab7d920e4340f12 X-Google-Attributes: gid1014db,public X-Google-Thread: 103376,dab7d920e4340f12 X-Google-Attributes: gid103376,public From: brennanw@pond.com (William C Brennan) Subject: Re: C is 'better' than Ada because... Date: 1996/08/21 Message-ID: #1/1 X-Deja-AN: 175596777 references: <4 <4vb399$kt8@mtinsc01-mgt.ops.worldnet.att.net> <4vb5st$b5r@krusty.irvine.com> <321AE6D8.41C67EA6@mailgw.sanders.lockheed.com> organization: FishNet newsgroups: comp.lang.ada,comp.lang.c,comp.lang.cobol Date: 1996-08-21T00:00:00+00:00 List-Id: In article <321AE6D8.41C67EA6@mailgw.sanders.lockheed.com>, Mike Roske wrote: > Adam Beneschan wrote: > > Having the same information in two or more places in the program has > > long been recognized as a major source of errors introduced during > > maintenance. > > Exactly. And this same problem occurs in both C _AND_ Ada language > programs. Ada gives you a nice way to avoid it, but engineers who > write structured software will use preprocessor definitions in C to > define _in ONE PLACE_ size (and other) information about data structures. > > Ergo, as both languages provide a mechanism to solve the single > definition problem, neither is "better" in this category. Well, both C and Ada do supply a mechanism to support a centralized, single-point name definition for the upper-bound or size of an array (or of an enumeration type, etc). But this does not mean that C's and Ada's mechanisms are equally "good". The C mechanism requires the programmer to define new names for the upper-bound and size. For one thing, this just unnecessarily pollutes the name space. It also puts the extra onus on the programmer to maintain the connection between an array type name and its upper-bound name. Standards may be employed by the staff to make this a simple mapping (e.g., "NameArray" and "NameArrayMax"), but I've never seen standards like this actively enforced in a project. One reason it isn't even this simple has to do with C's null-terminated strings. where you may need up to three constants: size of the array, upper-bound of the array, maximum number of non-null characters in the array. This sometimes means making up 3 names and keeping their uses all straight. The Ada mechanism embeds the naming convention into the language, so that its use is consistent throughout (e.g., "NameArray" and "NameArray'Last"). The compiler actually understands the meaning of "NameArray'Last", it's not some relationship the programmer needs to maintain as in C. The Ada mechanism enforces consistency, and keeps the size of the name-space down. This is cleaner and to my mind "better". -- Bill Brennan brennanw@pond.com