Introducing Nullable Reference Types in C#. Is there hope for D, too?

Jonathan M Davis newsgroup.d at jmdavisprog.com
Fri Nov 17 11:22:16 UTC 2017


On Friday, November 17, 2017 09:44:01 rumbu via Digitalmars-d wrote:
> I know your aversion towards C#, but this not about C#, it's
> about safety. And safety is one of the D taglines.

Completely aside from whether having the compile-time checks would be good
or not, I would point out that this isn't actually a memory safety issue. If
you dereference a null pointer or reference, your program will segfault. No
memory is corrupted, and no memory that should not be accessed is accessed.
If dereferencing a null pointer or reference in a program were a memory
safety issue, then we'd either have to make it illegal to dereference
references or pointers in @safe code or add additional runtime null checks
beyond what already happens with segfaults, since aside from having
non-nullable pointers/references, in the general case, we can't guarantee
that a pointer or reference isn't null. At best, the compiler can detect it
in certain instances (e.g. when a variable was initialized to null or
assigned null, and it wasn't passed to anything else before it was used),
but in most cases, it can't know.

So, this is purely about the compiler detecting a certain class of bug in
programs and giving a warning or error when it does, not about memory
safety.

- Jonathan M Davis



More information about the Digitalmars-d mailing list