object.enable() anti-pattern

Duncan Booth duncan.booth at invalid.invalid
Wed May 8 10:27:53 EDT 2013


Steven D'Aprano <steve+comp.lang.python at pearwood.info> wrote:

> I'm looking for some help in finding a term, it's not Python-specific
> but does apply to some Python code.
> 
> This is an anti-pattern to avoid. The idea is that creating a resource
> ought to be the same as "turning it on", or enabling it, or similar

I've come across this under the name 'two-phase construction', but as a 
desirable(!?) pattern rathern than as an anti-pattern.

In particular Symbian used it throughout as originally their C++ 
implementation didn't support exceptions. Instead they had a separate 
cleanup stack and objects that require cleanup were pushed onto that stack 
after being fully constructed but before calling the initialisation that 
required cleanup. See 
http://www.developer.nokia.com/Community/Wiki/Two-phase_construction


-- 
Duncan Booth



More information about the Python-list mailing list