FAQ for newbies who see pure @safe nothrow @nogc

Jonathan Marler via Digitalmars-d digitalmars-d at puremagic.com
Wed Jan 28 14:32:54 PST 2015


I believe we have reached consensus in our discussion about how 
to solve the issues of having some function attributes use a '@' 
and some not.

void foo() pure @safe nothrow @nogc;

I'd like to put the following question/answers somewhere that we 
can point newbies to so that when someone asks again, the 
discussion can be quenched immediately by simply directing them 
to the FAQ.  Maybe that means we link them to this post, maybe it 
means we add it to the site somewhere.  Feel free to improve.  
Here they are:

Why do some function attributes have a '@' and some dont?
-----------------------------------------------------------

Simple answer, "Words that are considered "keywords" don't 
require a '@', and non-keywords do".  A list of keywords is found 
here http://dlang.org/lex.html#Keyword.  This includes pure and 
nothrow, but does not include safe or nogc.

Why don't we make all the function attributes keywords?
-----------------------------------------------------------

A keyword cannot be an identifier. Since 'int' is a keyword, it 
cannot be used as a variable name, function name, etc. Because of 
this, if you add a new keyword, any code that was using that 
keyword before is now broken.  As D matures more keywords may be 
added but we are also trying to figure out the best set of 
function attributes. Instead of adding and removing keywords all 
the time, we use the '@' symbol until it becomes clear the new 
word should be a keyword.

Why do we have to use a '@' if the word is not a keyword?
-----------------------------------------------------------

It's possible to allow words to be function attributes that are 
not keywords, however, the D leadership feels that having a word 
serve as a function attribute in one context and an identifier in 
another is bad.


More information about the Digitalmars-d mailing list