virtual-by-default rant

Marco Leise Marco.Leise at gmx.de
Fri Mar 23 02:05:21 PDT 2012


Am Sun, 18 Mar 2012 04:49:12 +0100
schrieb "F i L" <witte2008 at gmail.com>:

> On Sunday, 18 March 2012 at 03:27:40 UTC, bearophile wrote:
> > F i L:
> >
> >> I'm a bit confused. Reading through the virtual function's 
> >> docs (http://dlang.org/function.html#virtual-functions) it 
> >> says:
> >> 
> >> "All non-static non-private non-template member functions are 
> >> virtual. This may sound inefficient, but since the D compiler 
> >> knows all of the class hierarchy when generating code, all 
> >> functions that are not overridden can be optimized to be 
> >> non-virtual."
> >
> > This is so much theoretical that I think this should be removed 
> > from the D docs. And to be put back when one DMD compiler is 
> > able to do this. Otherwise it's just false advertising :-)
> >
> > Bye,
> > bearophile
> 
> Dammit, I was afraid someone would say something like that. Well 
> at least it's a good goal. It is a bit of false advertising 
> though, honestly it should just be marked "implementation in 
> progress" or something like that.
> 

"the D compiler knows all of the class hierarchy when generating code"
This is just wrong, and if that was the base for deciding on virtual as default, I believe it is natural to think about it again.

Otherwise it should read "if you deal with non exported classes and don't use incremental compilation as well as refrain from compiling your code into static libraries, a D compiler can optimize methods to be non-virtual. As of the time of writing [...] no such compiler exists."

Now I feel better :)

-- Marco



More information about the Digitalmars-d mailing list