Keyword to avoid not null references

Namespace rswhite4 at googlemail.com
Mon Apr 23 08:06:44 PDT 2012


On Monday, 23 April 2012 at 14:50:14 UTC, Adam D. Ruppe wrote:
> On Monday, 23 April 2012 at 14:31:05 UTC, Namespace wrote:
>> Yes, that's what i wrote a site before. Otherwise you couldn't
>> use it in other modules, that's right.
>
> yeah i'll fix that next time i work on it.
>
>> I wouldn't write for all the objects which i would check
>> "method_with_not_null_object(ConvertToNotNull(f_obj));"
>
> The idea is to use NotNull!T to store your stuff,
> so there's no need to convert.
>
>> Why this reluctance against a keyword to check a normal Object
>> which is passed as parameter, e.g. @notNull Foo f?
>
> Because the hardware already does that, for the most part.
> That's what "access violation" means.
>
> The hard part is figuring out /why/ it is null, and the
> not null type helps that by catching it when you store
> it instead of when you use it.

So if i wouldn't want such annoying debugging for a simple error 
(which gave me no further information), i must catch this stupid 
access violation by myself with assert/enforce or i use for all 
relevant objects NotNull? That is very inconvenient...
And all that because NullPointer Exceptions or checks to assume 
not null (even with a explicit keyword!) would decrease the speed?


More information about the Digitalmars-d-learn mailing list