comp.lang.ada
 help / color / mirror / Atom feed
From: "James S. Rogers" <jimmaureenrogers@worldnet.att.net>
Subject: Re: More questions...
Date: 1999/03/08
Date: 1999-03-08T00:00:00+00:00	[thread overview]
Message-ID: <7bvn7g$rpm@bgtnsc03.worldnet.att.net> (raw)
In-Reply-To: 7bvb4j$lt0$1@remarQ.com


Michael Young wrote in message <7bvb4j$lt0$1@remarQ.com>...
>I have two questions about Ada; more will certainly follow.
>
>1) I've heard it said here that Ada, compared to other languages, is
>"reader-friendly" at the expense of being "writer-unfriendly". I
>understand the need to be reader friendly. I'm curious why you feel it
>is friendlier to read than, say, C++.

C and, because of C compatibility, C++ syntax is written to minimize the
number of keystrokes required to create a program.  In the early 1970's
this was viewed as a way of increasing programmer productivity.
Unfortunately,
C++ has taken the very terse syntax of C and added new functionality
while trying not to increase the number of additional keywords and
operators.
The result is a heavy overloading of already heavily overloaded operators.
Think of all the uses of the '*' and '&' operators in C++.  Correct
understanding
of these operators is highly context dependent.

Some examples taken from page 79 of "Object Oriented Programming
Using C++" by Ira Pohl:

int      i = 5;     // i is located in memory with rvalue 5
int*    p = &i;   // p is located in memory with rvalue &i
int&   r = i;      // r and i are the same object
int&* s = p;   // s and p are the same object

Now, the example above seems a little confusing.  It claims that r and i are
the
same object. At the same time it is true that references such as r are
implemented using pointers.  C++ simply provides a cleaner and safer
way to use a pointer when it is declared as a reference.  The statement
above would lead you to believe that r is merely an alias for i.

The nearest Ada equivalents to the C++ examples above are:

i : aliased integer := 5;    -- i is located in memory and is initialized
with the 5
type Int_Access is access all integer; -- define a general access type
p : Int_Access := i'access; -- p is located in memory with value of i'access

Ada does not have a direct equivalent to references.  In fact, Ada access
types
are as safe as C++ references while also being useful in all Ada data
structures.
C++ references are always constants.  A reference cannot change the object
it references. The reference object may or may not be constant.

C++ reference types cannot be elements of an array because references must
be initialized, while arrays cannot be initialized in C++.

As far as how readable the two languages are, try the following test.

Find a person who does not know Ada or C++.
Show that person the following code fragments.

#include <streams.h>
main ()
{
   for(int Count = 1; Count < 11; Count++)
      cout << Count << endl;
}

with Ada.Text_Io;
procedure Count_To_Ten is
begin
   for Count in 1..10 loop
      Ada.Text_Io.Put_Line(Integer'Image(Count));
   end loop;
end Count_To_Ten;

Ask this person what each code fragment does.

>2) Robert Dewar stated some time ago that finalize should be used
>sparingly because of performance concerns. Is this still true of GNAT
>3.11? More broadly, is this a language issue, or a feature specific only
>to certain GNAT or other implementation? Destructors in C++ are simply
>normal function calls. Are controlled types significantly different from
>other types to make this unrealistic?

This is not a compiler specific issue.  It is a language level issue.


Controlled types have the overhead of calling finalize each time an object
of the controlled type goes out of scope. Other types in Ada do not call a
finalize procedure when they go out of scope. Finalization is also called
during assignment operations for all temporary objects created and destroyed
during the actual assignment operation. Ada uses temporary objects so
that the case where A := A is properly handled.

C++ needs constructors for all classes because C++ requires dynamic
allocation and deallocation of objects to achieve polymorphism.  Ada allows
the programmer to decide whether or not to use dynamic allocation and
deallocation. Ada can achieve polymorphism with or without dynamic
allocation. This means that Ada does not always need a destructor.
Robert Dewar was warning against the use of Controlled types because they
impose an overhead which may not be necessary.  If your design uses no
dynamic allocation you may not need the facilities of Controlled types.

Jim Rogers
Colorado Springs, Colorado






  parent reply	other threads:[~1999-03-08  0:00 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1999-03-07  0:00 More questions Michael Young
1999-03-08  0:00 ` Steve Doiel
1999-03-08  0:00 ` James S. Rogers [this message]
1999-03-08  0:00   ` Hyman Rosen
1999-03-10  0:00     ` Matthew Heaney
1999-03-09  0:00 ` Samuel Mize
1999-03-09  0:00   ` Hyman Rosen
1999-03-10  0:00   ` robert_dewar
1999-03-09  0:00 ` Samuel Mize
replies disabled

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