Is it true scope declarations are being removed?

Jonathan M Davis jmdavisProg at gmx.com
Sun Jan 23 17:51:20 PST 2011


On Friday 21 January 2011 06:10:26 Sean Eskapp wrote:
> Someone mentioned to me that scope declarations, e.g.
> 
> scope class A{}
> or
> scope A myNewObject;
> 
> are being removed from the language. Is this true? If so, how will
> RAII-type classes be implemented?

std.typecons.scoped is the replacement for the builtin scope declaration. scope 
declarations are going away because they're inherently unsafe. Why they are then 
being put into the library, I'm not quite sure, other than the fact that D 
doesn't _stop_ you from doing unsafe stuff, it just seriously discourages it. I 
suppose that the big problem with having it in the language itself that the 
library solution doesn't quite have is that having it in the language kind of 
implies that it's okay and reasonable to do, which it isn't. It makes sense in 
specific circumstances, where you're know what all of the code involved is doing 
and can be sure that no reference to the scoped class will escape. And even 
then, why didn't you just make it a struct in the first place? There _are_ uses 
for scoped classes, but they're really not supposed to be the norm. They're 
unsafe, and you're begging for bugs if you use them heavily.

- Jonathan M Davis


More information about the Digitalmars-d mailing list