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.3 required=5.0 tests=BAYES_00,INVALID_MSGID autolearn=no autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,2a993df02f6d82f1 X-Google-Attributes: gid103376,public From: "James S. Rogers" Subject: Re: More questions... Date: 1999/03/08 Message-ID: <7bvn7g$rpm@bgtnsc03.worldnet.att.net>#1/1 X-Deja-AN: 452461571 References: <7bvb4j$lt0$1@remarQ.com> X-MimeOLE: Produced By Microsoft MimeOLE V4.72.2106.4 Organization: AT&T WorldNet Services Newsgroups: comp.lang.ada Date: 1999-03-08T00:00:00+00:00 List-Id: 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 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