Difference between revisions of "DIP79"

From D Wiki
Jump to: navigation, search
(Adding DIP79 skeleton)
 
(Rationale)
Line 29: Line 29:
  
 
== Rationale ==
 
== Rationale ==
TODO
+
In D classes all non-final and non-template methods are virtual by default.
 +
<syntaxhighlight lang="d">
 +
class C
 +
    /* virtual */ void someMethod(){}
 +
    /* virtual */ void someOtherMethod(){}
 +
    ...
 +
}
 +
</syntaxhighlight>
 +
 
 +
This in theory reduce some kind of bugs, when one forget to mark method as virtual. On the other hand it leads to some speed penalty.
 +
To improve speed you could mark your methods as final like this:
 +
 
 +
<syntaxhighlight lang="d">
 +
class C
 +
{
 +
    final void someMethod(){}
 +
    final void someOtherMethod(){}
 +
    ...
 +
}
 +
</syntaxhighlight>
 +
 
 +
This works well, but is somehow annoying and tiresome to mark all methods as final. So some patterns has been introduced:
 +
 
 +
<syntaxhighlight lang="d">
 +
class C
 +
{
 +
// make all methods final
 +
final:
 +
    /* final */ void someMethod(){}
 +
    /* final */ void someOtherMethod(){}
 +
    ...
 +
}
 +
</syntaxhighlight>
 +
<p>This is more handy and leads to less typing, but it has some drawbacks. If you need add few methods which are virtual or some members, you are forced to put them before <strong><code>final:</code></strong>. This is too limiting.</p>
 +
<p>
 +
Negation of attributes will remove these limits.
 +
</p>
  
 
== Description ==
 
== Description ==

Revision as of 08:38, 28 May 2015

Title: Negation of attributes
DIP: 79
Version: 1
Status: Draft (in progress)
Created: 2015-05-28
Last Modified: 2015-05-28
Author: Daniel Kozák
Links: [1]

Abstract

Proposal for a syntax change which will allow negation of attributes like (final, pure, nothrow, @nogc) without the need for new keywords.

Rationale

In D classes all non-final and non-template methods are virtual by default.

class C
    /* virtual */ void someMethod(){}
    /* virtual */ void someOtherMethod(){}
    ...
}

This in theory reduce some kind of bugs, when one forget to mark method as virtual. On the other hand it leads to some speed penalty. To improve speed you could mark your methods as final like this:

class C
{
    final void someMethod(){}
    final void someOtherMethod(){}
    ...
}

This works well, but is somehow annoying and tiresome to mark all methods as final. So some patterns has been introduced:

class C
{
// make all methods final
final:
    /* final */ void someMethod(){}
    /* final */ void someOtherMethod(){}
    ...
}

This is more handy and leads to less typing, but it has some drawbacks. If you need add few methods which are virtual or some members, you are forced to put them before final:. This is too limiting.

Negation of attributes will remove these limits.

Description

TODO

Alternatives

TODO

Copyright

This document has been placed in the Public Domain.