Opt-out polymorphism?

Jonathan M Davis jmdavisProg at gmx.com
Sun Feb 13 17:54:36 PST 2011


On Sunday 13 February 2011 17:40:39 bearophile wrote:
> Jonathan M Davis:
> > And honestly, in most cases, I think that what you're trying to do is
> > just plain begging for bugs. It is kind of cool that C# found a
> > relatively clean way to deal with it, but I honestly don't know what
> > it's useful for. I'd be worried about a program which overrode
> > non-virtual functions. It's highly likely to cause bugs.
> 
> C# designers are _not_ stupid or ignorant people :-)

I never claimed that they were. They cleaned up how overriding works in 
comparison to C++, and they given essentially the same options for overriding as 
C++ only they definitely do it better.

However, just because it's possible to do something in a particular language 
doesn't mean that it's a good idea to do it. I seriously question that it's 
_ever_ a good idea to have a function which isn't virtual but can be overridden. 
What reasonable use case does that have. I've never seen it, and I've definitely 
seen bugs caused by having functions not be virtual and yet still overridden. C# 
definitely improves over C++ in this regard, but the ability to override without 
polymorphism is of questionable value. The C# designers chose to have it in the 
language just like C++ did but do it better. The Java and D designers chose to 
make overriding and virtual functions intrinsically linked so that you can't 
override anything that isn't virtual.

No, the C# designers aren't stupid - far from it - but that doesn't mean that 
allowing non-virtual functions to be overridden is a good idea.

- Jonathan M Davis


More information about the Digitalmars-d-learn mailing list