digitalmars.D.learn - RAII limitations in D?
- Timothee Cour via Digitalmars-d-learn (20/20) Aug 21 2014 What would be a good answer to this article?
- Dicebot (1/1) Aug 21 2014 http://dlang.org/phobos/std_typecons.html#.RefCounted
- Timothee Cour via Digitalmars-d-learn (6/7) Aug 21 2014 That doesn't work with classes though; is there any way to get a ref
- Jonathan M Davis (6/15) Aug 21 2014 It can be made to work with classes and probably should be.
- Adam D. Ruppe (7/8) Aug 21 2014 It's own publication date: Feb 2009. The D struct has changed a
- Kagamin (13/26) Aug 21 2014 Even for C# those are not really problems. Returning from
What would be a good answer to this article? http://swiftcoder.wordpress.com/2009/02/18/raii-why-is-it-unique-to-c/ Especially the part mentioning D:{ 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++=E2= =80=99s combination of smart pointers and RAII, such as returning handles from functions, multiple handles in the same scope, or handles held by multiple clients. } This morning I was pointing to some deprecated usage of scope mentioned in docs (EMAIL:scope classes mentioned in tutorials, but deprecated). The pull request (https://github.com/D-Programming-Language/dlang.org/pull/637/files= ) mentions using struct or classes allocated on the stack via typecons.scoped. However what about the RAII usage mentioned in the above article that allows C++ to return handles for eg (impossible via scope), that get deterministically destroyed?
Aug 21 2014
On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:That doesn't work with classes though; is there any way to get a ref counted class? (and btw RefCounted should definitely appear in http://dlang.org/cpptod.html#raii)
Aug 21 2014
On Friday, 22 August 2014 at 03:00:01 UTC, Timothee Cour via Digitalmars-d-learn wrote:On Thu, Aug 21, 2014 at 7:26 PM, Dicebot via Digitalmars-d-learn < digitalmars-d-learn puremagic.com> wrote:It can be made to work with classes and probably should be. There's no fundamental reason why it can't. It's probably just more complicated. - Jonathan M DavisThat doesn't work with classes though; is there any way to get a ref counted class? (and btw RefCounted should definitely appear in http://dlang.org/cpptod.html#raii)
Aug 21 2014
On Friday, 22 August 2014 at 02:22:16 UTC, Timothee Cour via Digitalmars-d-learn wrote:What would be a good answer to this article?It's own publication date: Feb 2009. The D struct has changed a lot since then, getting new features ( disable, postblit, more reliable destructor) and bugs notwithstanding is pretty well on point nowadays. All the stuff mentioned in there works now.
Aug 21 2014
On Friday, 22 August 2014 at 02:22:16 UTC, Timothee Cour via Digitalmars-d-learn wrote:Especially the part mentioning D:{ 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. }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 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.
Aug 21 2014