On Tue, Jun 15, 2004, Guido van Rossum wrote: >Oliver: >> >> My only problem with PEP 310 is that the solution it proposes doesn't >> address the problem that the user of a class still needs to be the one to >> take care of ordering cleanup. So I would have prefered something that the >> coder of a class uses to tell the interpreter "any instance of this object >> needs deterministic cleanup", so the user can just be carefree when using >> that class. > > This is a fallacy, because the user still has to order the cleanup by > using the correct decorator. We can't afford to decorate *every* > function with this mechanism (method calls are already too expensive). My impression is that if integrated into the interpreter core, this wouldn't be particularly expensive. Fundamentally, it would look something like this: class C(RAII): def __init__(self): RAII.register(self) def foo(): x = C() then somewhere in the guts of the function calling mechanism, just before the scope unwinding, we'd have: for o in registered_objects: o.__finalize__() This is IMO an attractive nuisance, but I don't think it imposes much burden in execution speed. I do see the attraction as being similar to that of metaclasses and decorators: power provided to the end-developer with few demands for understanding. -- Aahz (aahz at pythoncraft.com) <*> http://www.pythoncraft.com/ "as long as we like the same operating system, things are cool." --piranha
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4