Newbie initial comments on D language - scope

Edward Diener eddielee_no_spam_here at tropicsoft.com
Wed Jan 30 14:32:48 PST 2008


Walter Bright wrote:
> Edward Diener wrote:
>> Understand that I am not saying that the user of an object of a scope 
>> class can not benefit from knowing, if he chooses, that the class is a 
>> scope class. Part of my suggestion about the keyword 'scope' in D is 
>> that when used it should force any object, even not normally scoped, 
>> to be destroyed when it goes out of scope. In this way the programmer 
>> can force a container of scoped objects to be destroyed immediately 
>> when it goes out of scope even though the container is not a scoped type.
> 
> You both have good points, but the problem with scoped classes are there 
>  are semantic problems with them if they are not carefully used.
> 
> I'm working on adding destructors to structs, which I'm thinking should 
> completely supplant scoped classes. RAII is a much more natural fit with 
> structs than it ever will be for classes.

Please reconsider that decision, especially in the light of the 
restrictions to structs in D which classes do not have. You would 
essentially be saying that any class designer, who would want to 
incorporate deterministic destruction in his class because of a need to 
free a resource upon class destruction, is constrained in D to using a 
struct rather than a class.

In that case why bother, since structs are so much less than a class in 
features. You might just as well say "I did not want the challenge of 
RAII in D, a GC language, so I will just kill it this way." If you 
really don't want RAII in D, which simply and fairly enough means you 
want the release of resources in your GC environment to always be done 
manually, just don't implement it at all. That is much more 
straightforward than attempting to support but doing it in such a way 
that makes it impossible for a class designer to implement it.

The current 'scope' keyword for RAII is very limited. My OP was not 
questioning that but objecting to the redundant way it had to be used 
even in that environment. However, making it more limiting rather than 
less limiting just kills it entirely IMO, where you should be seeking to 
go in exactly the opposite direction.



More information about the Digitalmars-d mailing list