www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - "scope attribute" vs "scope keyword" vs "scope storage class"

reply "Mike" <none none.com> writes:
This article (http://dlang.org/memory.html#raii) mentions a 
"scope attribute".

The following section (http://dlang.org/memory.html#stackclass) 
mentions a "scope storage class".

This deprecated list 
(http://dlang.org/deprecate.html#scope%20for%20allocating%20classes
20on%20the%20stack) 
states that the "scope keyword" has been deprecated.

Are all these terms ("scope attribute", "scope keyword", and 
"scope storage class") referring to the same thing?

Mike
Feb 05 2014
next sibling parent "Stanislav Blinov" <stanislav.blinov gmail.com> writes:
On Wednesday, 5 February 2014 at 11:01:00 UTC, Mike wrote:

 Are all these terms ("scope attribute", "scope keyword", and 
 "scope storage class") referring to the same thing?
"scope keyword" and "scope storage class" stay: http://dlang.org/function.html#parameters Although AFAIK it's not yet implemented.
Feb 05 2014
prev sibling next sibling parent "Cooler" <kulkin hotbox.ru> writes:
On Wednesday, 5 February 2014 at 11:01:00 UTC, Mike wrote:
 This article (http://dlang.org/memory.html#raii) mentions a 
 "scope attribute".

 The following section (http://dlang.org/memory.html#stackclass) 
 mentions a "scope storage class".

 This deprecated list 
 (http://dlang.org/deprecate.html#scope%20for%20allocating%20classes
20on%20the%20stack) 
 states that the "scope keyword" has been deprecated.

 Are all these terms ("scope attribute", "scope keyword", and 
 "scope storage class") referring to the same thing?

 Mike
Did you read "Rational" paragraph? "Note that scope for other usages (e.g. scoped variables) is unrelated to this feature and will not be deprecated."
Feb 05 2014
prev sibling parent reply "Dicebot" <public dicebot.lv> writes:
On Wednesday, 5 February 2014 at 11:01:00 UTC, Mike wrote:
 This article (http://dlang.org/memory.html#raii) mentions a 
 "scope attribute".

 The following section (http://dlang.org/memory.html#stackclass) 
 mentions a "scope storage class".

 This deprecated list 
 (http://dlang.org/deprecate.html#scope%20for%20allocating%20classes
20on%20the%20stack) 
 states that the "scope keyword" has been deprecated.

 Are all these terms ("scope attribute", "scope keyword", and 
 "scope storage class") referring to the same thing?

 Mike
D documentation has rather incosistent naming for attribute groups. - scope classes are deprecated, but usage of scope as storage class is still legal (it is expected to be a no-op for now) - scope storage class for function parameters is also accepted as no-op. For delegates it actually has a meaning. No deprecation. - scope statement as in scope(exit) was never suggested to be deprecated. - scope attribute most likely refers to declaration of scope classes and this is deprecated with them
Feb 05 2014
next sibling parent "Kagamin" <spam here.lot> writes:
On Wednesday, 5 February 2014 at 15:43:45 UTC, Dicebot wrote:
 For delegates it actually has a meaning. No deprecation.
It's the same meaning as for scope classes though. And the same unsafety.
Feb 06 2014
prev sibling parent reply "Brad Anderson" <eco gnuk.net> writes:
On Wednesday, 5 February 2014 at 15:43:45 UTC, Dicebot wrote:
 D documentation has rather incosistent naming for attribute 
 groups.

 - scope classes are deprecated, but usage of scope as storage 
 class is still legal (it is expected to be a no-op for now)
Couldn't "scope" allocating a class on the stack just be considered an optimization that can be applied if the scope storage class become fully implemented?
 - scope storage class for function parameters is also accepted 
 as no-op. For delegates it actually has a meaning. No 
 deprecation.
No-op just because it hasn't been implemented yet, right?
Feb 06 2014
parent reply "Dicebot" <public dicebot.lv> writes:
On Thursday, 6 February 2014 at 19:01:52 UTC, Brad Anderson wrote:
 On Wednesday, 5 February 2014 at 15:43:45 UTC, Dicebot wrote:
 D documentation has rather incosistent naming for attribute 
 groups.

 - scope classes are deprecated, but usage of scope as storage 
 class is still legal (it is expected to be a no-op for now)
Couldn't "scope" allocating a class on the stack just be considered an optimization that can be applied if the scope storage class become fully implemented?
I think so. Scope classes were unsafe because of leaking references but if `scope` is actually implemented to assure safety it becomes perfectly valid thing to do.
 - scope storage class for function parameters is also accepted 
 as no-op. For delegates it actually has a meaning. No 
 deprecation.
No-op just because it hasn't been implemented yet, right?
Yes. And there is no clear definition either.
Feb 06 2014
parent "Marc =?UTF-8?B?U2Now7x0eiI=?= <schuetzm gmx.net> writes:
On Thursday, 6 February 2014 at 22:16:30 UTC, Dicebot wrote:
 On Thursday, 6 February 2014 at 19:01:52 UTC, Brad Anderson 
 wrote:
 Couldn't "scope" allocating a class on the stack just be 
 considered an optimization that can be applied if the scope 
 storage class become fully implemented?
I think so. Scope classes were unsafe because of leaking references but if `scope` is actually implemented to assure safety it becomes perfectly valid thing to do.
If you declare something as scope, it is expected to have its destructor called at the end of the scope. Therefore, this behavior needs to be guaranteed. Theoretically of course, the memory could still be allocated on the heap and freed after destruction (or even just marked as destroyed and letting the GC clean it up), but this will probably not have advantages over stack allocation, except maybe for large objects.
Feb 07 2014