On 03/02/2018 08:36 AM, Paul Moore wrote:
> On 2 March 2018 at 15:09, <ooom...@gmail.com> wrote:
>> We must be discussing a different RAII. That is the raison d'etre of RAII:
>> RAII directly addresses this problem in an exception-safe way that does not
>> burden the resource user at all.
> RAII works in C++ (where it was initially invented) because it's used
> with stack-allocated variables that have clearly-defined and limited
> scope. In my experience writing C++, nobody uses RAII with
> heap-allocated variables - those require explicit allocation and
> deallocation and so are equivalent to having an explicit "close()"
> method in Python (or using __del__ in CPython as it currently exists).
Very good point. I'm not sure the OP considered this when proposing
That said, In C++, there are a number of ways of making heap-allocated
objects more RAII-like. These include smart pointers that do reference
counting and reference borrowing. They work pretty well when used as
designed, but they do require some programmer understanding and
intervention to use correctly and leaks can and do happen. Smart
pointers are pretty good hacks as far as they go, without a garbage