scope keyword - a maintenance nightmare?

Bill Baxter dnewsgroup at billbaxter.com
Fri Aug 17 13:36:36 PDT 2007


Guenther Brunthaler wrote:
> * There is is no equivalent to MODULA 2s "Definition Modules". While I think it is a good idea to get rid of C++'s primitive "header" files, there must still be some means of separating interface descriptions from the actual code. Otherwise, you always have to ship the complete source code to anyone who just wants to use some interface as a client. Consider writing a plugin for OpenOffice.org that way...

Like others have said, D has .di files that let you separate interface 
from implementation.  And the nice thing is the compiler can even 
generate them for you.  Unfortunately what it generates is pretty ugly. 
  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.

> * Maintenance-Nightmare with "auto" (now "scope").

I don't think scope is really meant to be used in the way that you want 
to use it.  Scope means the class is destroyed when it goes out of 
scope.  It is only meant to be for classes used within one scope. 
Period.  So if you had a pre-existing class that was already in use in 
lots of code, chances are good that they would be violating this "only 
one scope" rule, for instance by returning the scope class from a 
function.  So scope simply doesn't aim to be a general purpose mechanism 
for deterministic destruction.  It's probably most like using auto_ptr 
in C++.

What you want seems to be more like a reference counting scheme, like a 
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.  It would be much more 
widely useful than scope.

--bb



More information about the Digitalmars-d mailing list