auto classes and finalizers ~ dtor means RAII ?

Mike Capp mike.capp at gmail.com
Thu Apr 6 01:34:59 PDT 2006


In article <e12fva$29gr$1 at digitaldaemon.com>, kris says...
>
>Mike;
>
>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.

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


cheers
Mike





More information about the Digitalmars-d mailing list