RFC: Proposal: Deterministic Object Destruction
On Friday, March 2, 2018 at 2:43:09 PM UTC, Chris Angelico wrote:
> On Sat, Mar 3, 2018 at 1:18 AM, ooomzay wrote:
> > On Friday, March 2, 2018 at 8:16:22 AM UTC, Paul Rubin wrote:[snip]
> >> controlling stuff like file handles
> >> with scopes (like with "with") is fine.
> > How does with work for non-trivial/composite objects that represent/reference multiple resources or even a hierarchy of such objects where all the resources held must be released in a timely fashion when finished with?
> Can you give me an example that works with RAII but doesn't work in a
> 'with' statement?
My claim is about the relative elegance/pythonic nature of RAII w.r.t. 'with'. Probably with enough coding and no ommissions or mistakes 'with' could do achieve the same result that RAII does automatically without any
burden on the user.
Consider the hierarchy/tree of resource-holding objects postulated above... Presumably __enter__, __exit__ (or functional equivalent) would have to be implemented at every layer breaking the invariance. Thus complicating and making less robust every object it touches.