Keyword to avoid not null references

Namespace rswhite4 at googlemail.com
Sat Apr 21 14:40:45 PDT 2012


My question is, why D hasn't got an explicit Keyword to check at 
compile time for non null references?
I understand that such check when they're implicit and refer to 
all objects they slow down the programm, but why doesn't exist an 
explicit keyword like @ref or a simple '@' before the Object name 
or value.
Right now it's very annoying because i get a cryptical error 
message "Access violation" without any further informations and I 
have to debug. Only that way I can find where the Null references 
would access and then, why _and_ where the null references came 
from. That sucks.
I hate it and so i write in every method to avoid null references 
"assert(obj !is null);". Now i get an assertion if obj is null 
and also the file and line. 50% less work then before.
But it's still a runtime error and explicit work which can easily 
be checked by the compiler at compile time. Then i know: "oh 
there are null references and there shouldn't be any". So what 
are the reasons against a special keyword to let the compiler 
check for non references? I didn't understood it. I heard similar 
regressions from C# and Java, so why didn't D made it better and 
did implement something for that?

Some variants I have already seen: const Foo @obj, const @Foo obj 
or my favourite: const @ref Foo obj.

Greetz


More information about the Digitalmars-d-learn mailing list