scope keyword - a maintenance nightmare?

Guenther Brunthaler gb at dont.spam.me.invalid
Fri Aug 17 22:45:03 PDT 2007


Bill Baxter Wrote:

> It doesn't seem to expect that humans will be reading them for some 
> reason.  But there's no reason why it couldn't do a better job.

I agree.

di files are exactly the type of thing I was looking for.

And even if they don't look as beautiful as manually-written files - in C++ there isn't even a way to extract header files automatically from the source files.

There is also no-one stopping the developer from manually "beautifying" what D's .di file extractor has output.

If di files only were part of the language rather than optional extensions!

> C++ boost::shared_ptr, which gets destroyed immediately when all 
> outstanding references to it are gone.  That would indeed be a nice 
> addition to D, and has been discussed before.

Well, in C++ object destruction is also not based on reference counts, and RAII still works fine.

Perl and Python already implement destructors the reference-counted way, and it surely is a nice feature to have at one's disposal.

But it's a convenience feature, and one can as well live without it with a little bookkeeping effort: In C++ it is quite possible to add an object controlling a resource as an instance data member to some other object which has dynamically controlled life-time, i. e. allocated with "new" rather than on the stack.

But the predictable automated destruction still works: As soon as the containing object gets destroyed by "delete", the destructor of the contained instance-data sub-object will be triggered and clean up the resource as expected.

This allows the outer object's lifetime to be controlled by whatever means considered appropriate, may it be lexical scope, reference counting or even some other technique.

I actually assumed the "scope" keyword would work in a quite similar way in D!

But, if i got you right, are you suggesting "scope" only works on a lexical scope basis?

That it, a "scope" class object's lifetime does *not* depend on the lifetime of the object the variable is allocated within (such as the lexical scope *or* another object), but is *always* controlled by the lifetime of the lexical scope only?

That would be indeed a bad thing, at least for the way I use RAII.



More information about the Digitalmars-d mailing list