attribute bug?

Jonathan M Davis jmdavisProg at gmx.com
Fri Nov 9 21:28:23 PST 2012


On Saturday, November 10, 2012 05:18:17 goofwin wrote:
> On Friday, 9 November 2012 at 21:09:06 UTC, Jonathan M Davis
> 
> wrote:
> > Yes. public and protected are always virtual unless they're
> > final and don't
> > override anything (in which case, the compiler can choose to
> > make them non-
> > virtual). private and package are always non-virtual. IIRC
> > though, the docs
> > do need to be updated, since they imply that package is
> > virtual, even though
> > that's definitely not the case and isn't supposed to be the
> > case.
> > 
> > - Jonathan M Davis
> 
> It is very interested. I thought that 'package' is same as
> 'internal' from C#.

package restricts access to the same package. D has no concept like C#'s 
internal, because it doesn't have assemblies.

> I don't like that public, protected methods
> is virtual and private, package is non-virtual implicitly. I
> think that implicit behaviour is bad in most cases. And why can't
> i change this behaviour explicitly for example by means abstract
> attribute?
> 
> PS: Sorry for my bad English.

The language is more complicated if you can explicitly choose whether a 
particular function is virtual or not. It also causes a number of bugs. C++ 
has issues with it all the time. It certainly _can_ be done, but the language 
designers chose to go the Java route of making virtuality implicit. On the 
whole, it's exactly what you want.

Generally, public functions need to be virtual. If they don't, you can mark 
them as final. And it makes no sense for a protected function to be non-
virtual. So, both of them are virtual.

It doesn't really make sense for private functions to be virtual. If you want 
them to be virtual, just use protected. And if private were virtual, then that 
would really hurt performance, and everyone would be forced to mark all of 
their private functions as final to avoid it. So, it just makes more sense to 
make them non-virtual.

package is more debatable, and some people have argued that it should be 
virtual, but Walter Bright and Andrei Alexandrescu don't think that it really 
makes sense to. I'd have to go digging through the archives for the main 
newsgroup though to find a post where they discuss it to tell you exactly what 
they said.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list