A few questions

Namespace rswhite4 at googlemail.com
Sat Jul 28 01:20:56 PDT 2012


> This is a NotNull I just implemented. It is designed to create 
> a strict
> division between things that can be null, and those that 
> cannot. The idea
> being that the programmer should be aware of it when he needs 
> to convert
> between them, and whole call graphs can more easily be made 
> free of
> null checks.

Foo f = new Foo();
some_function(NotNull!Foo(f)); <-explicit conversion and because 
it's a struct it's better to deliver it by ref.

// ---

Foo f = new Foo();
some_function(f);

// ...

void some_function(Foo f) in {
assert(f !is null);
} body {

^--- explicit. Unnecessary write effort.

A struct as solution to avoid not null references is a bad 
solution. It is a nice play tool but as solution it is crap. To 
pack my object into a struct with ensures that it is not null, 
what's the difference if i use only structs and avoid classes? 
Why should i initialize first my object and put it then into a 
struct if i can even use only structs?
That isn't comprehensible to me.


More information about the Digitalmars-d-learn mailing list