Slow performance compared to C++, ideas?

H. S. Teoh hsteoh at quickfur.ath.cx
Thu Jun 6 07:17:10 PDT 2013


On Thu, Jun 06, 2013 at 11:16:01AM +0200, Michal Minich wrote:
> >On Thursday, June 06, 2013 10:42:26 Michal Minich wrote:
> >>On Thursday, 6 June 2013 at 05:52:28 UTC, Jonathan M Davis
> 
> >>What about case when you want to introduce new final method of
> >>the same name as already existing final method in base (c# uses
> >>'new' for this)
> >>
> >>class Base { final void foo () }
> >>class Derived : Base { new void foo () }
> >>
> >>what would be in place of 'new' in D?
> >
> >We could probably use new to mean the same thing, but I confess that
> >even allowing this seems incredibly bad to me. You end up with a base
> >class function which isn't being overidden looking like it's being
> >overriden in a derived class. And even if it's obvious when look at
> >Derived's declaration thanks to the new, anything which is derived
> >from Derived would just be marked with override. So, it would be
> >incredibly easy to think that calling Base.foo would call Derived.foo
> >or the foo function of the class derived from Derived.
> >
> >So, certainly my initial reaction is to say that because Base.foo was
> >marked with final, it shouldn't be possible for any of its derived
> >classes to have a function with the same signature.
> 
> That can cause problem for author of base class - if he add any
> final method, he can break derived classes he may not know of.
> Example - if you update your external lib you are using in your
> project, and it happens that new version of some base has 'search'
> final function added, and you happen to have fn with same name in in
> your derived, you must now rename all your usages of 'search'
> function... (i would be preferable if you could just add new on in
> your derived class 'search').
[...]

Wait, why would this be a problem? D already requires that you specify
'override' if you're overriding a base class method. Since final methods
cannot be overridden, if the derived class declares a method of the same
signature as a base class method, it should be obvious that it's *not*
overriding anything. There's no need to use 'new'.


T

-- 
Nearly all men can stand adversity, but if you want to test a man's
character, give him power. -- Abraham Lincoln


More information about the Digitalmars-d mailing list