🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.std.c++
Article #3509

Re: Proposal: Reconcile Inheritance and Inlining

#3509
From: Rich Hickey
Date: Mon, 26 Feb 1996 17:35
88 lines
3356 bytes
In message <4gkscd$8rl@news.BelWue.DE> - 
kuehl@uzwil.informatik.uni-konstanz.de (Dietmar Kuehl) writes:
:>
:>Hi,
:>
:>Rich Hickey (hickeyr@ibm.net) wrote:
:>[Explanation of the proposal removed]
:>
:>: class B{
:>: public:
:>:    virtual int foo()const=0;
:>:    //...
:>: };
:>
:>: explicit class D:public B{
:>: public:
:>:   int foo()const{return data;}
:>:   //...
:>: private:
:>:   int data;
:>: };
:>
:>: void fred(const D &d)
:>:    {
:>:    d.foo();  //as if d.D::foo(); - inlined
:>:    }
:>
:>: void ethel(const B &b)
:>:   {
:>:   b.foo();	//even if b is a D, virtual function call (as always)
:>:   }
:>
:>
:>: It cannot be otherwise accomplished in the language, i.e. it requires an extension.
:>
:>I think it is easy to accomplish the thing you want to do in the language:
:>
:>  class E: public B {
:>  public:
:>    int foo_inline() const { return data; }
:>    int foo() const        { foo_inline(); }
:>  private:
:>    int data;
:>  };
:>
:>  void foo(E const &e)
:>  {
:>    e.foo_inline(); // inline. Note that you know exactly the type of 'e'
:>    e.foo();        // virtual as ever
:>  }
:>
:>Although I agree with you that your proposal is nicer to use, your
:>claim that it cannot be implemented in the language is wrong...

What your are suggesting does not accomplish the same thing, i.e. it does 
not, in the language, accomplish an inline call to a virtual function called 
via a reference or pointer.

void fred(const D &d)
   {
   d.foo();  //as if d.D::foo(); - inlined
   }

I want to avoid wrapper classes, duplicate functions etc. The technique you 
are suggesting has always been available yet has seen little use (that I am 
aware of). It is much more than a matter of transparency or convenience. 
Developers may not consider your solution viable for a number of 
possible reasons.

Some of the differences are:

Double the number of functions in the concrete class, with the accompanying 
confusion and maintenance headaches.

An inability to easily change code that uses the base to use the derived, or 
vice-versa, due to the different names.

Thus, in spite of your technique having been available to them, most 
developers still consider hierarchy vs. inlining as an either-or choice.

Rich
---
[ To submit articles: Try just posting with your newsreader.  If that fails,
                      use mailto:std-c++@ncar.ucar.edu
  FAQ:    http://reality.sgi.com/employees/austern_mti/std-c++/faq.html
  Policy: http://reality.sgi.com/employees/austern_mti/std-c++/policy.html
  Comments? mailto:std-c++-request@ncar.ucar.edu 
]
Technical Details
Message-ID: <4gqika$j00@news-s01.ny.us.ibm.net>
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
References: <4gkas9$4o84@news-s01.ny.us.ibm.net>

Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!chronicle.mti.sgi.com!austern
From: hickeyr@ibm.net (Rich Hickey)
Newsgroups: comp.std.c++
Subject: Re: Proposal: Reconcile Inheritance and Inlining
Date: 26 Feb 1996 09:35:55 PST
Organization: -
Approved: austern@isolde.mti.sgi.com
Message-ID: <4gqika$j00@news-s01.ny.us.ibm.net>
References: <4gkas9$4o84@news-s01.ny.us.ibm.net>
NNTP-Posting-Host: isolde.mti.sgi.com
X-Original-Date: 25 Feb 1996 20:59:54 GMT
X-Newsreader: NeoLogic News for OS/2 [version: 4.2]
X-Auth: PGPMoose V1.1 PGP comp.std.c++
 iQBVAwUBMTHvkky4NqrwXLNJAQFr6wH/YsjJ8/uMSK0WlfW1sidzE+nLC7Ny41aW
 o9Z58PAKHs15Ojs93dq+VMDIla6N8U2YmozkjrMuMaI81K8P5ZuAEA==
 =+cCt
Originator: austern@isolde.mti.sgi.com