Disallow null references in safe code?

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Sat Feb 1 08:19:32 PST 2014


On 1/31/14, 5:14 PM, Xinok wrote:
> I don't know where the community currently stands on non-nullable types
> in D, so this idea may be based on a bit of ignorance. Assuming there
> are some technical issues preventing non-nullable types from being
> implemented, I had a different idea that may be somewhat of a
> compromise. As you've gathered by now, it's simply to disallow
> nullifying references in safe code.
>
> The idea is simply that safe functions can only call other safe
> functions, so null references should be practically non-existant ...
> except that's an ideal which can't be reached with this restriction
> alone. There are two obvious issues:
>
> * There's no way to guarantee input is free of null references
> * Trusted functions may return objects with null references; it's
> currently not convention to avoid null references in trusted code
>
> Albeit that, I think such a restriction could be helpful in preventing
> bugs/crashes and writing correct code, at least until we can get
> non-nullable types.

It's an interesting idea, but I don't think it would work well for the 
reasons others mentioned.

Andrei



More information about the Digitalmars-d mailing list