auto classes and finalizers ~ dtor means RAII ?

Georg Wrede georg.wrede at nospam.org
Thu Apr 6 04:49:28 PDT 2006


Mike Capp wrote:
> kris says...
> 
>> Instead of making the dtor illegal for GC types, why not remove the
>> 'auto' keyword from this realm altogether, and just use the
>> existance of a dtor as the class RAII indicator?
> 
> The trouble is that this wouldn't make the RAII behaviour apparent to
> somebody reading the code. They'd have to go and look at the class
> definition. I'm happy to do a little extra typing for the sake of
> code clarity here, in the same way that I thought C#'s insistence on
> having "in" and "ref" arguments marked as such by calls as well as
> decls was a nice touch.

FWIW, I fully agree.

>> What to do about those classes that need a dtor-like construct, but
>> cannot be deemed RAII? Be explicit about closing them, using the
>> close() or dispose() approach.
> 
> Can you give some concrete examples of such 'awkward' classes? I'm
> not saying they don't exist, but I'm not assuming that they must,
> either. The "dispose" (anti-)pattern is, frankly, awful. It's "Wrong
> By Default" taken to the extreme.

Yes, and thinking of a class that needs "destructing", which then may 
happen much later (at GC time), or never at all -- is just insanity.



More information about the Digitalmars-d mailing list