Slow performance compared to C++, ideas?

Joseph Rushton Wakeling joseph.wakeling at webdrake.net
Fri Jun 7 05:11:51 PDT 2013


On 06/06/2013 07:10 PM, Rob T wrote:
> My understanding is that final on it's own would be an error if the same named
> function was virtual in the base class, otherwise you would have to specify
> "final override". If that understanding is not correct, then I agree that would
> be a source of hidden errors.

The problem as I understand it is as follows.

First, consider this scenario: there's a base class.  You've created a subclass
in it with a method, foo(), which is not in the base class.  Now, suppose that
the base class adds its own foo(), which is virtual.

Now, your subclass will fail to compile [*] unless you tweak its own foo(), and
apart from renaming foo() in your subclass, you have only two options: (i) to
override the base class foo() or (ii) to "hide" or replace the base class foo().
 So, the language should require you to be unambiguous and indicate explicitly
which.  Obviously "override" or "final override" will do for the first case.

But what if you allow "final" to be the keyword for the second, "hide the base
method" case?  (This is my understanding of the proposal I replied to.)

If you do, then consider the alternative scenario.  You have a base class with a
virtual method bar().  You _mean_ to override it with a final method, but
accidentally type just "final" and not "final override".  The compiler will
accept this without warning, because it takes "final" to mean your explicit
indication to "hide the base class method", and it may take you some time to
realize that the base class method is incorrectly being hidden instead of
overridden.

So, that's why I suggest an alternative keyword to indicate the programmer's
desire to hide rather than override the base class method, and C#'s choice of
"new" seems as good as any.

That's assuming that we want to allow base class methods to be hidden, but the
case made by C# is fairly compelling:
http://forum.dlang.org/thread/yzsqwejxqlnzryhrkfuq@forum.dlang.org?page=24#post-op.wx8biyx7eav7ka:40stevens-macbook-pro.local


[* Technically it need not fail to compile but the compiler would have to assume
a default behaviour and warn you in the absence of an explicit indicator of your
desires.  In C# the default is to hide rather than override the base class
method, and it warns you if you don't explicitly indicate "override" or "new".]


More information about the Digitalmars-d mailing list