On Tuesday, 31 March 2015 at 07:48:08 UTC, w0rp wrote:

I argue that instead of catching NullPointerExceptions, you should make them never happen. This is where Option types come in. Rather than using T*, use an Option!T and force yourself to always check for null gracefully. Also use Some!T (a.k.a NotNull) and get classes and pointers which are verified via contracts that they are not null.

I have already implemented such a thing here.

https://w0rp.com/project/dstruct/dstruct/option/

If you don't like it, you can always implement a similar thing yourself.

Now at this point you might wish for this to gain some benefits from being a language feature. I think I will agree, but who knows if that will ever happen.

Maybe this a good direction.

A pointer or reference is replaced by a struct (a pointer holder?), and the struct will check if the pointer is null.

It is a good idea, I could check the pointer myself now, and stopping worring about server crashing, that's enough.

Excellent job, Thank you!

Reply via email to