TEAM-ADA Archives

Team Ada: Ada Programming Language Advocacy


Options: Use Forum View

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

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

Print Reply
Ben Brosgol <[log in to unmask]>
Reply To:
Ben Brosgol <[log in to unmask]>
Wed, 14 Oct 1998 13:11:55 -0700
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;
   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".


Ben Brosgol
[log in to unmask]