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.9 required=5.0 tests=BAYES_00 autolearn=ham autolearn_force=no version=3.4.4 X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 103376,b0d569080889afd6 X-Google-Attributes: gid103376,public From: Richard D Riehle Subject: Re: A question for my personal knowledge. Date: 1999/05/19 Message-ID: <7ht3rr$e65@dfw-ixnews5.ix.netcom.com> X-Deja-AN: 479075511 References: <1VEZ2.1515$I51.88140@carnaval.risq.qc.ca> <37372A84.641F2133@bigfoot.com> <7h8oe8$2js$1@cf01.edf.fr> <37382B0C.A95B6745@bigfoot.com> <7h9o21$9v4$1@nnrp1.deja.com> <7h9pei$aut$1@nnrp1.deja.com> <373AC668.4824FF07@decada.enet.dec.com> <7hfctj$1kb4@drn.newsguy.com> <7hqcni$p8r@sjx-ixn1.ix.netcom.com> <7hsh9g$rjp@sjx-ixn4.ix.netcom.com> Organization: Netcom X-NETCOM-Date: Tue May 18 8:24:11 PM CDT 1999 Newsgroups: comp.lang.ada Date: 1999-05-18T20:24:11-05:00 List-Id: In article , Hyman Rosen wrote: >Richard D Riehle writes: >> As to comparing the languages, such comparisons are nearly always >> fruitless. > >But you started it! You said that to the uninformed, C++ looks simpler >than Ada, but that with deeper understanding, the opposite becomes >apparent. I invited you to show me some code which demonstrates this. I apologize for having "started it." I should know by now that language comparisons are the equivalent of wading through fresh taffy on a warm autumn afternoon, sweet but difficult when a quick movement is necessary. I am going to decline this invitation, but decline with a thank you. The thank you is because your challenge has opened a new avenue of thought for me, an avenue I am going to explore by creating just such an example for the book I am currently writing. It is clear from the discussion that I might be able to make a contribution by creating such an example. As a point of information, I will use the C++ Vector class example, published in most textbooks about C++, the . This example works in the comparison because it is nearly always designed with all four of the member functions mentioned in my earlier post. An interesting feature of C++ design is the frequent use of * and & for variables and function return types. In this respect, Ada is quite different. That is, we do not use pointers and references in quite the same way, mostly because of the increased risk of using these in safety-critical applications. Yes, I know of the availability of memory.h and other features to reduce the risk of raw pointers. And this certainly does help C++ to be a little safer. I do not want to give the impression that I think C++ is evil, or even bad. It is a very good language. In my earlier post, I tried to emphasize that some aspects of C++ are less than wonderful and some aspects of Ada are less than wonderful. My actual point was somewhat obscured by the way I presented it. Someone had mentioned that the syntax of a C++ class was more intuitive or easier, or some such thing. My point was that the simplicity seems simpler than it really is. Class design, whether in Ada, Eiffel, or C++ is not so simple. Some kinds of designs will be better in Ada. Others might be better in C++. It is, however, a mistake to think that the simplicity of the class format in C++ makes it easier than the class format in Ada -- or vice versa. >I don't know Ada, and I don't feel like learning it right now, but I >think I could follow an example you post. So show me an object which >requires a constructor and user-defined assignment operator in C++, >but only a simple declaration and no such operator in Ada. Or if I >misunderstood, just show me *something* where Ada's object model lets >you do away with things that C++ requires. The textbook example of the Vector class is a good example. Not only does one need to include a constructor (at least one), but also a copy constructor, a destructor, a friend function for the + operator, and a lot of other stuff one would not find in a typical Ada package for the Vector class. On the other hand, I might very well want to design a Vector class that had all that stuff. I would not require a "friend" function because Ada's model would not require such a thing. If I designed the type as, type Vector (Size : Positive) is limited private; I would need a copy procedure to emulate assignment (but no separate copy constructor), and would probably overload the equality operator. I actually have a wide range of options for this design. If I design it as, type Vector (<>) is private; then I will, in fact need something equivalent to a constructor such as a function that returns the constrained type, function Make (Size : Positive) return Vector; and will probably want to create a copy procedure for this type. Again, Ada practitioners will consider other design options such as use of a controlled type to implement an adjust procedure to prevent the potential for constraint errors at assignment. The point is, I have a wide range of options for designing either an elegantly simple Vector or an elegantly complicated one. I can also design an Ada type that resembles the C++ class, with all the attendant overhead. It is more difficult, I think, to design a C++ class that resembles an Ada type. This will be an interesting example to design for my book. It will require some thought, some compilations, and some testing. I am not going publish the code here since I intend to use it in my book. This is more than I intended to say on this subject. I don't plan to say anymore. (Say Amen, someone). I know this will not satisfy you. When you are ready to study Ada I think you will enjoy what you discover. Until then, enjoy the experience with C++. I am enjoying my experience with it too. Richard Riehle richard@adaworks.com http://www.adaworks.com