Why does nobody seem to think that `null` is a serious problem in D?

Neia Neutuladh neia at ikeran.org
Tue Nov 20 16:26:08 UTC 2018


On Tue, 20 Nov 2018 15:29:50 +0000, Kagamin wrote:
> On Tuesday, 20 November 2018 at 11:11:43 UTC, aliak wrote:
>> This only applies to little scripts and unittests maybe.
>>
>> Not when you're writing any kind of relatively larger application that
>> involves being run for longer or if there's more possible permutations
>> of your state variables.
> 
> Umm... if you write a larger application not knowing what is a reference
> type, you're into lots and lots of problems.

A pointer to a struct is a reference type.

There are plenty of cases where you need reference semantics for a thing. 
If you are optimistic about the attentiveness of your future self and 
potential collaborators, you might add that into a doc comment; people can 
either manually do escape analysis to check if they can store the thing on 
the stack, or allocate on the heap and pass a pointer, or embed the thing 
as a private member of another thing that now must be passed by reference.

If you're pessimistic and don't mind a potential performance decrease, you 
might defensively use a class to ensure the thing is a reference type.


More information about the Digitalmars-d-learn mailing list