On 8/2/10 10:33 AM, bearophile wrote:
Mafi:
If you want a NullPointerException as part of your program flow, you can
use enforce() (in std.contracts I think). I don't think catching a
NullPointerException in a big code block where you don't know which
dereferencing should fail is good style.
enforce() is not a panacea (panchrest); as far as I know DMD doesn't inline any
function that contains enforce(). So sometimes an assert() is better,
especially if it's inside a contract (precondition, etc).
DesignByConstrac-style programming is not something that just happens, you have
to train yourself for some time for it.
Bye,
bearophile
The problem isn't how to check it on a case-by-case basis, there are
plenty of ways to check that a given pointer is non-null. The problem is
debugging _unexpected_ null dereferences, for which a NPE or its
equivalent is very helpful, a segfault is _not_.
Sorry, didn't mean to reopen a can of worms, just wanted to be clear.
--
rwsims