[Exceptional C++ Style] Item 18 - Virtuality

Kevlin Henney kevlin at curbralan.com
Tue Jan 4 07:23:55 EST 2005


In message <opsj2t36x5v17jmk at smtp.ntlworld.com>, Ric Parkin 
<ric.parkin at ntlworld.com> writes
>On Tue, 4 Jan 2005 11:12:19 -0000, Paul Grenyer 
><paul at paulgrenyer.co.uk>  wrote:
>> 2. I agree with all the ideas and arguments for the NVI pattern. 
>>However, I
>> am in two minds about the extra code overhead. I suppose in many ways the
>> overhead is similar to things like the pimpl idiom, which I often 
>>use,   but
>> do find time consuming to expand and retract. I think I'd find the 
>>same   with
>> NVI.
>
>The perceived overhead does feel irritatingly high - you have to write 
>all  this extra forwarding stuff before you can actually use it, which 
>slows  down your train of thought.

And, importantly, you will probably never use it. If it had other 
benefits it might be worth it, but unfortunately it makes the concept of 
an interface -- an essentially simple idea to convey -- a fragmented and 
complex one. This is the smell of "speculative generality" that Martin 
Fowler mentions in Refactoring, quoting Brian Foote.

>This is something that a simple refactoring  tool *ought* to be able to 
>do fairly easily.

Yes. Perhaps some C++ programmers are attracted to NVI because they (1) 
like ritual complexity and (2) do not have proper tools, whether mental 
or software?

>Other things from the original - I've always found the DoXXXX naming 
>slightly icky , but haven't found anything better. Given you need two 
>names, and they ought to have the main bit in common, I think you need 
>a  wart like "Do" or "Impl" or a trainling underscore. Suggestions 
>welcome.

If you don't bother with NVI, you don't have to come up with alternative 
names ;-) I agree, I have always found such naming schemes both icky and 
a hint that something is not quite right.

Kevlin
-- 
____________________________________________________________

   Kevlin Henney                   phone:  +44 117 942 2990
   mailto:kevlin at curbralan.com     mobile: +44 7801 073 508
   http://www.curbralan.com        fax:    +44 870 052 2289
   Curbralan: Consultancy + Training + Development + Review
____________________________________________________________



More information about the Effective-cpp mailing list