Subject: Re: [boost] [Review] GGL review starts today, November 5th
From: Steven Watanabe (watanabesj_at_[hidden])
Date: 2009-11-23 18:42:45
Patrick Horgan wrote:
> Steven Watanabe wrote:
>> Patrick Horgan wrote:
>>> Steven Watanabe wrote:
>>>> FWIW, non-virtual destructors are the norm in Boost.
>>>> I strongly dislike the idea of having a policy enabling
>>>> virtual destructors.
>>> Steven, could you tell me the reason for this?
>> There aren't a lot of virtual function in Boost either.
> A quick grep in trunk shows about 1200 virtual methods including 136
> virtual destructors under boost.
I haven't actually checked, but I my guess is that this
is a fairly small fraction of Boost. There are 72 subdirectories
in Boost, I think.
>> In ggl, the only virtual functions I see are in exception classes.
>>> I have always thought that if you had virtual methods, you should
>>> have a virtual destructor since the derived class has something
>>> different about it and if being destructed via a reference or
>>> pointer to base, the wrong thing could happen without a virtual
>>> destructor! Educate me please. I've never heard of any reason to
>>> avoid a virtual destructor if you already had virtual methods.
>>> Obviously I'm missing something about something I thought I understood.
>> I don't think so. If you're using virtual functions in the
>> normal OO way, a virtual destructor almost always
>> makes sense. (The use of virtual in Boost.Exception
>> is somewhat different. virtual is being used as an
>> implementation detail to separate a fragment of the
>> interface of a concrete type from the rest of the type
>> in order to minimize dependencies. It isn't being used
>> for polymorphism at all)
> But there are virtual destructors in exception of course (isn't
> exception pretty, elegant code btw?) I'm still a bit confused. Are
> you saying that destroying from a base class reference can't be a problem?
In this particular instance destroying through a base class
reference is impossible.
> Of course that's true if the derived class doesn't ever add any extra
> dynamic value or system state, but even in that case, surely you'd
> want to have the virtual destructor anyway if there is a need for
> virtual functions, so that if someone less thoughtful was
> extending/maintaining it later, the design would keep those sorts of
> mistakes from being made. It's defensive programming.
Sorry, I was referring to the specific case of exception_ptr_base
where there are virtual functions and a non-virtual destructor.
> But what I was really asking about, was when you said:
>> Steven Watanabe wrote:
>>> FWIW, non-virtual destructors are the norm in Boost.
>>> I strongly dislike the idea of having a policy enabling
>>> virtual destructors.
> It seems there's lots of virtual destructors in Boost, and you haven't
> told me why you are against them.
I'm not. I'm against having a Policy controlling whether a class has
a virtual destructor, like this:
template<class T, class HasVirtualDestructor = boost::mpl::true_>
> In what way are they bad?
> In this statement you seem to come out against them quite strongly.
> You seem to be saying that you want it to be a rule that they are not
> to be used. Am I mis-reading this somehow?