[RFC] Throwing an exception with null pointers

Walter Bright newshound2 at digitalmars.com
Thu Apr 17 05:31:48 UTC 2025


On 4/16/2025 2:49 PM, Dave P. wrote:
> Where the annotations are really valuable is for function arguments and return. 
> Can this argument be null or not? Now the compiler can help you instead of you 
> having to memorize the documentation of every function you call.

I've long since given up on memorizing the documentation of each parameter. Too 
many functions! I just google it, it just takes a sec.


> I’ve consistently applied these annotations to my C projects and it works 
> wonders. Many classes of mistakes are caught at compile time.

I agree that compile time detection is always better than runtime.

I get a null pointer seg fault now and then. I look at the stack trace, and have 
it fixed in the same amount of time it takes you.

I don't worry about it, because it is not a memory corruption issue.

The time I spend tracking down a null pointer seg fault does not even register 
among the time I spend programming.

You're not wrong. But it's a cost/benefit thing.

 > Somethings are a
 > dynamic property of your system, and for that there is a nullability sanitizer
 > that can detect at runtime if a `_Nonnull` pointer gets a null value (usually
 > from a data structure that was not properly initialized).

I don't see how a runtime detector can work better than a seg fault with stack 
trace.



More information about the Digitalmars-d mailing list