Non-null objects, the Null Object pattern, and T.init

Andrei Alexandrescu SeeWebsiteForEmail at erdani.org
Fri Jan 17 16:13:50 PST 2014


On 1/17/14 1:29 PM, Walter Bright wrote:
> On 1/17/2014 1:10 PM, H. S. Teoh wrote:
>> On Fri, Jan 17, 2014 at 11:43:59AM -0800, Walter Bright wrote:
>> [...]
>>> I've almost never had a problem tracking down the cause of a null
>>> pointer. Usually just a few minutes with a debugger and getting a
>>> backtrace.
>>
>> I think this depends on the kind of code you write.
>>
>> In callback-heavy code, usually when you're multiplexing between many
>> simultaneous request/response chains, these kinds of problems are very
>> hard to track down.  You'll see the null pointer somewhere in your
>> callback's context structure, but no amount of backtrace will help you
>> go any further because they all end at the event dispatch loop pretty
>> shortly up the stack, which doesn't tell you where in the chain of
>> events the null came from.
>
> What you do then is go back as far as practical, then put asserts in.

That hardly helps. The source of the problem is not detecting that it 
occurs, it's avoiding it in the first place by initializing data 
appropriately.

Andrei




More information about the Digitalmars-d mailing list