A few questions

Simen Kjaeraas simen.kjaras at gmail.com
Sat Jul 28 08:46:30 PDT 2012


On Sat, 28 Jul 2012 10:20:56 +0200, Namespace <rswhite4 at googlemail.com>  
wrote:

>> 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.

The conversion from a pointer to a struct containing a pointer should be
without cost when compiling with optimizations on. The effect is exactly
the same as with a pointer, which I hope you don't habitually pass by
reference.


> 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.

Huh? I believe you have misunderstood something here. The struct is a form
of smart pointer. It behaves like a pointer does, and lets you have
polymorphism, inheritance and all that stuff that comes with classes.
Granted, I have found a few issues with the version I posted (mostly to do
with subclassing). Most have been fixed in this version, but some are
unfixable until issue 1528 has been resolved.

-- 
Simen
-------------- next part --------------
A non-text attachment was scrubbed...
Name: NotNull.d
Type: application/octet-stream
Size: 5616 bytes
Desc: not available
URL: <http://lists.puremagic.com/pipermail/digitalmars-d-learn/attachments/20120728/16fecfca/attachment.obj>


More information about the Digitalmars-d-learn mailing list