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

Michel Fortin michel.fortin at michelf.ca
Fri Jan 17 18:18:13 PST 2014


On 2014-01-18 01:22:49 +0000, Walter Bright <newshound2 at digitalmars.com> said:

> First off, in all these scenarios you describe, how does not having a 
> null make it EASIER to track down the bug?

Implemented well, it makes it a compilation error. It works like this:

- can't pass a likely-null value to a function that wants a not-null argument.
- can't assign a likely-null value to a not-null variable.
- can't dereference a likely-null value.

You have to check for null first, and the check changes the value from 
likely-null to not-null in the branch taken when the pointer is valid.

-- 
Michel Fortin
michel.fortin at michelf.ca
http://michelf.ca



More information about the Digitalmars-d mailing list