Slow performance compared to C++, ideas?

Michal Minich michal.minich at gmail.com
Wed Jun 5 05:53:58 PDT 2013


On Monday, 3 June 2013 at 17:18:55 UTC, Andrei Alexandrescu wrote:
  override is not comparable
> because it improves code correctness and maintainability, for 
> which there is ample prior evidence. It's also a matter for 
> which, unlike virtual/final, there is no reasonable recourse.

Virtual by default makes it simpler to call method on object that 
is not initialized yet (constructor not called yet). This 
situation is possible regardless if virtual is default or not (it 
can just happen more easily). I think this calling virtual 
function in constructor should generate a warning. (I wouldn't be 
surprised if there is enhancement request filed for this already)

module test;
import std.stdio;

class Base
{
     this ()	{ writeln("Base.this"); foo();  }
     void foo () { writeln("Base.foo"); }
}

class Derived : Base
{
     this () { writeln("Derived.this"); }
     override void foo () { writeln("Derifed.foo"); }
}

void main () { auto d = new Derived; }

Program output:
Base.this
Derifed.foo // Derived.foo is called before object constructor
Derived.this


More information about the Digitalmars-d mailing list