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,LOTS_OF_MONEY autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,198c6302c4a0b0d7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-20 18:55:08 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!nntp.cs.ubc.ca!newsfeed.direct.ca!look.ca!wn1feed!wn2feed!worldnet.att.net!204.127.198.203!attbi_feed3!attbi.com!rwcrnsc52.POSTED!not-for-mail From: "Mark Lundquist" Newsgroups: comp.lang.ada References: <3c1dc786@pull.gecm.com> <1008601517.470745@edh3> <1008626816.690418@master.nyc.kbcfp.com> <1008690461.380980@master.nyc.kbcfp.com> <_xRT7.4398$xl6.682759@rwcrnsc54> <_T4U7.8960$xl6.990924@rwcrnsc54> Subject: Implicit instantiation (was Re: was Re: Ada / C++ comparison paper anymore) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 5.50.4133.2400 X-MimeOLE: Produced By Microsoft MimeOLE V5.50.4133.2400 Message-ID: Date: Fri, 21 Dec 2001 02:55:08 GMT NNTP-Posting-Host: 192.168.198.212 X-Complaints-To: abuse@attbi.com X-Trace: rwcrnsc52 1008903308 192.168.198.212 (Fri, 21 Dec 2001 02:55:08 GMT) NNTP-Posting-Date: Fri, 21 Dec 2001 02:55:08 GMT Organization: AT&T Broadband Xref: archiver1.google.com comp.lang.ada:18186 Date: 2001-12-21T02:55:08+00:00 List-Id: "Patrick Hohmeyer" wrote in message news:DK6U7.24955$Yq5.2627743@news20.bellglobal.com... > > Ok, an exemple : > > procedure X is > > generic > type Number is range <>; > type Num_Arr is array (Integer range <>) of Number; > function Mean(A : Num_Arr) return Number; > > function Mean(A : Num_Arr) return Number is > Sum : Integer := 0; > begin > for I in A'Range loop > Sum := Sum + Integer(A(I)); > end loop; > return Number(Sum/A'Length); > end Mean; > > > type T_Employes is array(Integer range <>) of Natural; -- employe numbers > type T_Employe_S is array(Integer range <>) of Natural; -- employe salaries > > function Sal_Mean is new Mean(Natural,T_Employe_S); > > Employes : T_Employes(1..1000); > Employe_S : T_Employe_S(1..1000); > Mean_Sal : Natural; > > begin > Mean_Sal := Sal_Mean(Employe_S); -- line 1 > Mean_Sal := Sal_Mean(Employes); -- line 2 > end X; > > --end code ----------------------- > > First, I know that identifiers as similiar as Employes and > Employe_S are bad. > You can easly mix them and thats exactly the point here. > > Line 1 is correct, we calculate the mean salary of our employes. > But Line 2 calculates the mean of the employe numbers. > This makes no sense, and thanks to Ada this dont even compile, > as I haven't defined the Mean function for the employe numbers The real problem there is that the programmer made a conscious choice to use the same type (Natural) for two unrelated abstractions. Next, they put themselves in the way of trouble by a deliberate choice of extremely error-prone names. And your point is that they are still protected, because to make it past the compiler they would have to screw it up in two places (the instantiation and the call) instead of just one. Look, your moron of a programmer now already has about a hundred ways to hose him/herself; what's the harm of letting them have one more, if that were the price of a much more powerful language for the rest of us? Your example code is a grenade with the pin pulled, with or without implicit instantiation. (I trust I don't need to give an example here...) I would not consider it a "great strength of Ada" for me to have to deal with labor-intenstive generics for the sake of a check that benefits only people who go out of their way to program badly. Ada is engineered for safety against normal human error, not error compounded by inexcusably lame programming practice. Best Regards, -- mark