Newbie initial comments on D language - scope
Jason House
jason.james.house at gmail.com
Tue Jan 29 10:11:20 PST 2008
Edward Diener Wrote:
> The first is the necessity of using an already scoped class by repeating
> the 'scope' decalation when creating an object of that class. Since the
> class itself has already been declared with the 'scope' keyword it seems
> absolutely redundant that the user of an object of the class must repeat
> 'scope' in his usage of that object. Surely the compiler is smart enough
> to know that the class is a 'scope' class and will generate the
> necessary code to automatically call the destructor of the class when it
> goes out of scope. In fact the user of this class via an instantiated
> object should not even care if it is a scoped class or not, so having to
> say it is again seems doubly wrong, although allowable.
It's already been clarified by others that scope is different than a reference counted object that's deleted immediately when no more references to it exist. The post that follows is under the assumption that this applies to the use of scope as defined in the D language.
RAII tends to require very specific usage semantics. Because of this alternate behavior (and requirements on usage), it makes complete sense to mark the variable as scope when used. I don't expect the addition or removal of the scope property of a class to be something that would not require code changes in other places.
One of the appeals of d to me is that it aims to reduce coding errors. This repeat of the use of scope feels like it's an attempt to keep scope usage both clear and correct.
More information about the Digitalmars-d
mailing list