DIP79

From D Wiki
Revision as of 08:38, 28 May 2015 by Kozzi11 (talk | contribs) (Rationale)
Jump to: navigation, search
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.