TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy

TEAM-ADA@LISTSERV.ACM.ORG

Options: Use Forum View

Use Monospaced Font
Show HTML Part by Default
Show All Mail Headers

Message: [<< First] [< Prev] [Next >] [Last >>]
Topic: [<< First] [< Prev] [Next >] [Last >>]
Author: [<< First] [< Prev] [Next >] [Last >>]

Print Reply
Subject:
From:
Ben Brosgol <[log in to unmask]>
Reply To:
Ben Brosgol <[log in to unmask]>
Date:
Wed, 14 Oct 1998 13:11:55 -0700
Content-Type:
text/plain
Parts/Attachments:
text/plain (46 lines)
John Harbaugh wrote:

>This illustrates a fundamental advantage of Ada:  It is difficult to
>write correct programs that have typos.

I agree in general, but there is one pitfall in the case of OOP (which by
the way is not unique to Ada).  If you misspell the name of a subprogram
intended to override an otherwise implicitly inherited operation, then you
do not override it even  though you think you have.  Example:

package Student_Pkg is
   type Student is tagged private;
   type Student_Class_Ref is access Student'Class;
   function Financial_Aid (Item : Student) return Natural;
   ...
end Student_Pkg;

with Student_Pkg; use Student_Pkg;
package Athlete_Pkg is
   type Athlete is new Student with private;
   function Financal_Aid( Item : Athlete) return Natural;
  -- Note mistake in spelling name of function
   ...
end Athlete_Pkg;

with Student_Pkg, Athlete_Pkg;
use Student_Pkg, Athlete_Pkg;
procedure Example is
   X : Student_Class_Ref := new Athlete;
   N : Natural;
begin
   ...
   N := Financial_Aid( X.all );  --(*)
end Example;

The dynamic binding at (*) invokes the Student version of Financial_Aid,
which is probably not what was intended.  To some extent the need to repeat
the subprogram specification in the package body reduces the risk of this
effect, since maybe the typo will be spotted if it appears twice, but it is
still a potential "gotcha".

Regards,

Ben Brosgol
[log in to unmask]

ATOM RSS1 RSS2