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,198c6302c4a0b0d7 X-Google-Attributes: gid103376,public X-Google-ArrivalTime: 2001-12-20 09:56:50 PST Path: archiver1.google.com!news1.google.com!newsfeed.stanford.edu!news-spur1.maxwell.syr.edu!news.maxwell.syr.edu!newsfeed.cwix.com!sjc-peer.news.verio.net!news.verio.net!ord-read.news.verio.net.POSTED!not-for-mail Newsgroups: comp.lang.ada From: Brian Rogoff Subject: Re: was Re: Ada / C++ comparison paper anymore In-Reply-To: Message-ID: 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> MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Date: Thu, 20 Dec 2001 17:56:50 GMT NNTP-Posting-Host: 192.220.65.223 X-Complaints-To: abuse@verio.net X-Trace: ord-read.news.verio.net 1008871010 192.220.65.223 (Thu, 20 Dec 2001 17:56:50 GMT) NNTP-Posting-Date: Thu, 20 Dec 2001 17:56:50 GMT Organization: Verio Xref: archiver1.google.com comp.lang.ada:18155 Date: 2001-12-20T17:56:50+00:00 List-Id: To which I reply "Don't do that!". It's quite easy to create similar contrived bug scenarios in Ada without automatic instantiation of generics using overloading, and, in fact, many very smart language designers believe that overloading is awful. I disagree, and think that by applying a bit of intelligence and good taste overloading makes programs more readable. To avoid this particular problem, I would avoid the automatic instantiation by not with-ing the generic unit and instantiating the subprograms that I want elsewhere and with-ing those. Pretty simple, huh? -- Brian On Wed, 19 Dec 2001, Patrick Hohmeyer wrote: > Mark Lundquist wrote : >> ... pushing for automatic instantiation of generics, bless you Mark! ... > 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. > > But with your auto-instanciation, I simply would write Mean > and nobody catched the error. It compiles and even *runs* fine, > only the results are completly nonsense. > > That's why I'm against auto-instantiations. > > People make bugs. And everything that is transformed auto-magicly > helps bugs to survive longer. > > -- > Patrick Hohmeyer >