'delete' keyword

%u wfunction at hotmail.com
Tue Jan 4 18:31:25 PST 2011


Hi,

I just found out that the 'delete' keyword is intended to be deprecated, and I
wanted to share several opinions about it and make a couple of suggestions:

- Please don't remove it, at least not in D version 2. The *main* reason I've
used D is its flexibility with regard to garbage collection -- it lets the
programmer optimize his programs in ways that are not possible otherwise.

- If you remove it, you'll also be forced to remove scope(), because of the
same "dangers" -- and hence lots of optimizations when using the stack simply
won't be possible, and D will just become a glorified C# in terms of memory
management. (I quit C# precisely because of D's greater flexibility in memory
management.)

- If you *MUST* remove it, do something else instead: Change it so it simply
redirects to a GC method, and have that GC method add the object to a list of
objects that should be analyzed before anything else for garbage collection
(effectively making the object become generation negative one). This will fix
safety issues (because there's no requirement for the object to be actually
freed, if there's references to it), it'll be efficient (since no collection
necessarily takes place at that moment), but it'll still give the programmer
control over object lifetimes, and prevent issues like midlife crisis. (I'll
still cry over the fact that the old 'delete' will be gone, but less than if
this feature wasn't present.) :)

- An alternative solution to removing 'delete' (which I would highly advocate)
is for it to still delete the object, but call a logging function (which can
be activated at run time) to write down which exact chunks of memory were
collected. That way, if an access violation later happens, the programmer can
simply look at the address and notice that it was previously allocated by
objects X, Y, and Z, and then he can look for where the problems were. I'd
personally say that this is probably better than any other solution, because
(a) the programmer can activate or deactivate the logging at will, and (b)
it'll facilitate debugging but still make D be the powerful language it is.

Again, PLEASE continue supporting the keyword, even if it means the program
has to be given a big red "COMPUTER HAZARD" stamp or something... :) otherwise
D will just no longer be the powerful language it is.

(I'm curious to see what people think of the debugging feature? Opinions are
very welcome!)


And thank you for making D the great language it is! :)


More information about the Digitalmars-d mailing list