On 1/16/2014 5:42 PM, Andrei Alexandrescu wrote:
Walter and I were talking today about the null pointer issue and he had the
following idea.

One common idiom to replace null pointer exceptions with milder reproducible
errors is the null object pattern, i.e. there is one object that is used in lieu
of the null reference to initialize all otherwise uninitialized references. In D
that would translate naturally to:

class Widget
{
     private int x;
     private Widget parent;
     this(int y) { x = y; }
     ...
     // Here's the interesting part
     static Widget init = new Widget(42);
}

I was thinking of:

      @property static Widget init() { ... }

Reply via email to