As I’m working getting the @gc
function attribute into D, the last remaining covariant attribute without contravariant inverse will be pure
. The biggest question will not be how useful it is because its use will be exactly like that of other contravariant attributes (@system
, throw
, and @gc
), no, the biggest question is syntax.
What are your preferences?
A few inspirations:
- Make
impure
a hard keyword, sopure
andimpure
falls into the same syntactical category asthrow
andnothrow
.
This has the downside of breaking code that has identifiers namedimpure
. I’d guess those would be rare, though. - Make
@impure
a compiler-recognized AtAttribute.
This has the downside of being asymmetric:pure
has no@
, but its inverse@impure
would have it. - Make
impure
a contextual keyword, i.e. a compiler-recognized identifier with special meaning in certain places, similar tobody
.
This has the downside that it breaks very specific code (e.g.int function() impure
) and that it uses contextual keywords which Walter really doesn’t like. This option is interesting for the base language when Option 1 is pursued in the next Edition. - ―???―