comp.lang.ada
 help / color / mirror / Atom feed
From: "Mark Lundquist" <no.spam@getalife.com>
Subject: Implicit instantiation (was Re: was Re: Ada / C++ comparison paper anymore)
Date: Fri, 21 Dec 2001 02:55:08 GMT
Date: 2001-12-21T02:55:08+00:00	[thread overview]
Message-ID: <gwxU7.16794$Ah.619003@rwcrnsc52> (raw)
In-Reply-To: DK6U7.24955$Yq5.2627743@news20.bellglobal.com


"Patrick Hohmeyer" <pi3_1415926536@yahoo.ca> 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






  parent reply	other threads:[~2001-12-21  2:55 UTC|newest]

Thread overview: 53+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-12-17 10:22 Ada / C++ comparison paper Martin Dowie
2001-12-17 14:42 ` Frode Tenneboe
2001-12-17 22:07   ` Hyman Rosen
2001-12-17 22:34     ` David C. Hoos
2001-12-17 22:37     ` Marin David Condic
2001-12-18  0:54       ` Ed Falis
2001-12-18  9:30         ` martin.m.dowie
2001-12-18 14:49           ` Marin David Condic
2001-12-18 17:51           ` Hyman Rosen
2001-12-19 16:10             ` Greg C
2001-12-20 14:41               ` Hyman Rosen
2001-12-20 20:16                 ` Greg C
2001-12-19 20:44             ` Wes Groleau
2001-12-19 20:47               ` Ed Falis
2001-12-20 18:16                 ` Ted Dennison
2001-12-20 19:12                 ` Richard Riehle
2001-12-18  1:16       ` Larry Kilgallen
2001-12-17 22:52     ` Matthew Heaney
2001-12-18 15:47     ` Hyman Rosen
2001-12-18 16:20       ` Pat Rogers
2001-12-18 17:00         ` Hyman Rosen
2001-12-18 17:28           ` Larry Kilgallen
2001-12-18 19:40         ` Brian Rogoff
2001-12-18 20:25           ` Hyman Rosen
2001-12-19  0:53           ` was Re: Ada / C++ comparison paper anymore Mark Lundquist
2001-12-19  1:47             ` Brian Rogoff
2001-12-19 18:20               ` Mark Lundquist
2001-12-19 19:39                 ` Patrick Hohmeyer
2001-12-19 19:38                   ` Mark Lundquist
2001-12-19 20:51                     ` Patrick Hohmeyer
2001-12-20 17:56                       ` Brian Rogoff
2001-12-20 18:48                         ` Patrick Hohmeyer
2001-12-20 19:20                           ` Brian Rogoff
2001-12-21  3:16                             ` Implicit instantiation (was Re: Ada / C++ comparison paper anymore) Mark Lundquist
2001-12-21  3:12                           ` Implicit instantiation (was Re: was " Mark Lundquist
2001-12-21  2:55                       ` Mark Lundquist [this message]
2001-12-20 20:22             ` was Re: Ada / C++ comparison paper anymore Ted Dennison
2001-12-20 20:57               ` Marin David Condic
2001-12-21 17:44               ` Richard Riehle
2001-12-21 17:51                 ` Marin David Condic
2001-12-19 18:20       ` Ada / C++ comparison paper Mark Lundquist
2001-12-20 20:27         ` Ted Dennison
2001-12-20 20:59           ` Marin David Condic
2001-12-21 14:26             ` Ted Dennison
2001-12-21 14:32               ` Marin David Condic
2001-12-21 15:11               ` Jean-Marc Bourguet
2001-12-20 22:30           ` tmoran
2001-12-20 22:36             ` Marin David Condic
2001-12-21 14:23             ` Ted Dennison
2001-12-21 18:46               ` tmoran
2001-12-21 19:09                 ` Ted Dennison
2001-12-21  2:46           ` Mark Lundquist
2001-12-21 14:28             ` Ted Dennison
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox