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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 X-Google-Thread: 103376,5af5c381381ac5a7 X-Google-NewGroupId: yes X-Google-Attributes: gida07f3367d7,domainid0,public,usenet X-Google-Language: ENGLISH,ASCII Path: g2news1.google.com!postnews.google.com!y4g2000yqy.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! Date: Tue, 8 Jun 2010 00:46:31 -0700 (PDT) Organization: http://groups.google.com Message-ID: <1c704c1e-1b2e-427f-ae0e-3b2a0f976c7c@y4g2000yqy.googlegroups.com> References: <03f84a0a-e070-43a9-9b68-920345f64f94@r27g2000yqb.googlegroups.com> NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1275983191 30805 127.0.0.1 (8 Jun 2010 07:46:31 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Tue, 8 Jun 2010 07:46:31 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y4g2000yqy.googlegroups.com; posting-host=137.138.182.236; posting-account=bMuEOQoAAACUUr_ghL3RBIi5neBZ5w_S User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.5; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3,gzip(gfe) Xref: g2news1.google.com comp.lang.ada:11462 Date: 2010-06-08T00:46:31-07:00 List-Id: On 7 Cze, 17:00, "Martin Krischik" wrote: > > It looks like virtual destructors amount for some 20-30% of all in my > > code. > > Now that is interesting. It's even more interesting than this, because in several cases I had to add the "virtual" keyword not because it was driven by design, but because the compiler complained about the lack of it. The g++ compiler gives a warning (-Wall) for each case where a class has at least one virtual function and non-virtual destructor. That is, in order to get a clean compile, I had to add the "virtual" keyword in several places where it was not necessary from the design point of view. In other words, the effective numbers are even lower than that. > It means that most of your classes are final as =A0 > the java guys would say. While I have always written under the premises = =A0 > that my classes might become child classes for something else. (rather parent classes, or to use the C++ terminology - base classes) In many projects classes can be divided into two groups: 1. "public", making a user API of the project (typical for libraries) 2. "private", for the implementation details The types from the first group *might* become parents for something provided by the user and it makes sense to defensively prepare them for this role. Even this is not always the case, for example *none* of the STL classes has a virtual destructor. Types from the second group are fully controlled by the project designer - this includes the closure of eventual hierarchy and all usage patterns. If instances of these types are not deleted by pointer to base then there is *no reason* to make their destructors virtual. And I try to avoid using pointer if they are not necessary. Note: if the project is not a library, then the first group is empty. > BTW: you are aware that if the parent class uses a virtual destructor the= n =A0 > the child class does as well - even when not explicitly specified? I am pedantic in my coding conventions and I always mark virtual stuff as being explicitly virtual. > > then you are probably trying to write Java in C++. > > I learned C++ before Java using IBM Open Class Library In other words, you have been exposed to the overly object-oriented style. :-) Try some modern libraries like Boost or POCO - they are a lot less focused on object orientation. =A0 > A string class with lazy copy, C++ library authors resigned from this idea long time ago. It's very ineffective in the multithreading environment. > Well and 90% of the classes =A0 > descending form IVBase. Guess what the V stands for. As I've already said - this design approach is representative for '80s. There is a reason for why today's most acknowledged libraries are not designed this way. -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4