DIP51

From D Wiki
Revision as of 12:47, 27 November 2013 by Turkeyman (talk | contribs) (Created page with "{| class="wikitable" !Title: !'''not-virtual-by-default''' |- |DIP: |51 |- |Version: |1 |- |Status: |Draft |- |Created: |2013-11-27 |- |Last Modified: |2013-11-27 |- |Author: ...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search
Title: not-virtual-by-default
DIP: 51
Version: 1
Status: Draft
Created: 2013-11-27
Last Modified: 2013-11-27
Author: Manu Evans

Abstract

Virtual calls are inefficient, and through extensive discussion, it has been shown that it is impossible for an optimiser to safely finalise virtuals in any useful capacity in a non-JIT/VM environment. This DIP proposes that class methods need to be non-virtual by default, or D classes will always yield inferior performance characteristics to other native languages.

In support of this change, introduction of the 'virtual' keyword will be required, and a deprecation process similar to the introduction of override will be followed. 'final' will be preserved, and remain useful to effectively 'seal' a hierarchy, in the same way as is useful in Java, C++, and C# (via 'sealed').

Example

class Base
{
  virtual f();
}

class Derived : Base
{
  override f();
}

...WIP