On 5/20/13 11:19 AM, Byron Heads wrote:
On Sun, 19 May 2013 17:36:17 -0400, Andrei Alexandrescu wrote:
OK, this is sensible. One question - would you be willing to type
symbols as NullType!T instead of T to avoid these issues?

Thanks,

Andrei

More boiler plate code for functions that take pointers.

void foo(T)(T t)
        if(isPointer!T)
{
     static if(isNullable!T)
        if(!t) throw ....
}

But this goes both ways. Regardless of the default, you'd sometimes need to distinguish between cases. You either hurt one half of your cases or the other half. In fact you are now showing the case that assumes non-nullable being the default.

May also introduce then need to check for objects in the init state
(default state)



outside of NonNull in stdlib, an attribute maybe a possible answer.

void bar(@nonnull SomeClass o)
{
        o = foo(); // if foo returns @nonnull, then check is not needed,
else needs a check added during assignment
}

there are a few compile time checks that can be done to prove o is not
null, if not the compiler adds runtime checks.

I think a parameterized type is a better match for non-null because it attaches to the type, not the symbol.

But really, checking for valid input is part of programming, might be
better to have lint integration that can help find these types of problems

Agreed.


Andrei

Reply via email to