Right now, what's the most important for the success and adoption of D?

Daniel Keep daniel.keep.lists at gmail.com
Sat Sep 29 07:03:22 PDT 2007



Patrick Kreft wrote:
> downs schrieb:
>> Max Samukha wrote:
>>> 1. More bugfixes in D 1.0. I would be happy to call it stable some
>>> day.
>>> 2. The problem with RAII (destructors are useless:
>>> http://www.digitalmars.com/d/archives/digitalmars/D/learn/destructors_7525.html
>>>
>>> and other threads)
>>> 3. GUI
>>
>> Seconded, especially the first. And the second. Third would be nice
>> too :)
>>  --downs
> 
> Hmm Second isnt an issue. I think it was misunderstood. Yeah D have GC
> and RAII, that means that u can explicit call a destructor and this will
> be executed.

No, it's not misunderstood.  It's *because* D uses garbage collection
that destructors are nearly useless.  An example from the thread:

class MyClass
{
    OtherClass a;
    this() {
       a = new OtherClass;
    }
    ~this() {
       delete a;
    }
}

This code is very dangerous because by the time ~this is executed, a may
already have been deleted.  It may not have been.  You *cannot* tell.
'a' will *probably* exist if you explicitly delete the object, or you
use RAII, but the problem is that as soon as you miss an object, or
decide to let the GC handle a single instance, the code becomes
dangerous and you can't rely on it.

This is solved slightly by having forcibly scoped class instances, but
these instances are themselves incredibly restricted precisely because
they can't escape their scope; meaning you can't return them out of
functions.

The problem, in a nutshell, is that because of the GC, a destructor
cannot safely act on or modify *any* GC-allocated memory, since you
never know when it's going to be destroyed.

	-- Daniel

P.S.  Insert general disclaimers about how there are corner cases and
exceptions to the above, but I'm far to lazy to point them all out.



More information about the Digitalmars-d mailing list