[RFC] Throwing an exception with null pointers
GrimMaple
grimmaple95 at gmail.com
Mon Apr 21 11:56:53 UTC 2025
On Monday, 21 April 2025 at 10:45:15 UTC, Richard (Rikki) Andrew
Cattermole wrote:
>
> That is the Swift solution to the problem, more or less.
My take here is that null pointers (references/whatever) just
_shouldn't be_, __period__. The compiler should disallow me to
generate a null pointer, unless specifically asked for - like
with `Nullable!MyType`. or, even better, `Optional!MyType` --
then we can finally ditch that "null pointer semantic" and use
"correct" terminology, because most often a null pointer is just
used as a quasi-optional type. Any memory allocations that end up
in a null pointer, eg `new` running out of memory, should result
in an Exception/Error, not returning null.
I think that having `NotNull!T` provides a soft transition from
having null to not having null at all -- it's fairly trivial to
append `MaybeNull!` to any var type that needs it; and then it's
fairly easy to just rename it to `Optional` c:
More information about the Digitalmars-d
mailing list