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,CP1252 Path: g2news2.google.com!postnews.google.com!y11g2000yqm.googlegroups.com!not-for-mail From: Maciej Sobczak Newsgroups: comp.lang.ada Subject: Re: Ada requires too much typing! Date: Mon, 7 Jun 2010 01:34:20 -0700 (PDT) Organization: http://groups.google.com Message-ID: References: NNTP-Posting-Host: 137.138.182.236 Mime-Version: 1.0 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable X-Trace: posting.google.com 1275899660 18231 127.0.0.1 (7 Jun 2010 08:34:20 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Mon, 7 Jun 2010 08:34:20 +0000 (UTC) Complaints-To: groups-abuse@google.com Injection-Info: y11g2000yqm.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: g2news2.google.com comp.lang.ada:12363 Date: 2010-06-07T01:34:20-07:00 List-Id: On 6 Cze, 14:04, "Martin Krischik" wrote: > > I suppose there must be some cost to doing this? or the language > > definition would require it to be always so. > > Yes indeed, you have virtual dispatch not only on the methods but on the = =A0 > instance variables as well. No, such concept does not even make sense - instance variables themselves have no behavior and therefore cannot be "overriden". With virtual inheritance there is only one copy of the given instance variable within the whole object, so even the word "dispatch" cannot be applied there, as "dispatch" relates to "choice" and there is no choice. > Main problem with multiple inheritance was in =A0C++ itself where default= is =A0 > =93fast=94 not =94save=94. No. Neither of these (non-virtual vs. virtual) is "fast" or "safe" in itself. Considering the performance aspect, the layout of variables within the object is determined *statically* (I have already explained that there is no "dispatch" involved), which means that there is no run-time cost in finding the given data item. All instance variables have some offset from the "beginning" of the object and that offset is computed statically, whether inheritance is virtual or not. There is no particular reason for any performance difference in data access, so it does not make any sense to say than one mode is "fast", while the other is not. Both are "fast" (it's C++, remember? ;-) ). Considering the safety aspect, the choice between non-virtual and virtual is design-dependent. Both make sense in some domain. For example, my mobile phone is able to send both text and multimedia messages. In both cases I might want to see the count of messages that were already sent and I want these counters to be *distinct*, not shared. This is a perfectly valid design (pseudo-code): class Countable; class TextMessager : public Countable; class MultimediaMessager : public Countable; class Phone : public TextMessager, public MultimediaMessager, ...; Now I have *separate* counters, both accessible with appropriate name paths (which makes perfect sense). Why is this a default? I don't know, but it's consistent with the fact that the whole object model is value-oriented, not interface-oriented. It's neither right nor wrong. (note: you might argue that the counter should be held by composition, not by extension - this is orthogonal to this discussion) > but main problem stay: not enough C++ programmer have known about virtual= =A0 > inheritance Again, that knowledge would not necessarily help them, as the use of virtual inheritance is not automatically justified. > The real lesson learned: =93doing it right=94 must be default Both ways are right. The default one is consistent with the overall object model. > and =93make it =A0 > fast=94 must be an optional extra Both are fast. -- Maciej Sobczak * http://www.inspirel.com YAMI4 - Messaging Solution for Distributed Systems http://www.inspirel.com/yami4