RAII limitations in D?

Kagamin via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Thu Aug 21 21:48:22 PDT 2014


On Friday, 22 August 2014 at 02:22:16 UTC, Timothee Cour via 
Digitalmars-d-learn wrote:
> Especially the part mentioning D:{
> D’s scope keyword, Python’s with statement and C#’s using 
> declaration all
> provide limited RAII, by allowing resources to have a scoped 
> lifetime, but
> none of them readily or cleanly support the clever tricks 
> allowed by C++’s
> combination of smart pointers and RAII, such as returning 
> handles from
> functions, multiple handles in the same scope, or handles held 
> by multiple
> clients.
> }

Even for C# those are not really problems. Returning from 
functions is not a problem: you just return it and that's it, 
because resource management is decoupled from types, the types 
have no RAII semantics and you can move them around however you 
want. On the other hand, in C# it's very easy to declare a 
resource, while in C++ you would need to learn all the black 
magic of RAII before you can declare a RAII type. Multiple 
handles in the same scope are not frequent, nested if's cause 
much more trouble. Handles held by multiple clients are even more 
rare, and it's usually easy to figure out lifetime for non-memory 
resources.


More information about the Digitalmars-d-learn mailing list