object.enable() anti-pattern

Dan Sommers dan at tombstonezero.net
Wed May 8 22:38:36 EDT 2013


On Wed, 08 May 2013 14:27:53 +0000, Duncan Booth wrote:

> 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.

Think of spinning off a thread:  initialize it synchronously, and then
let it execute asynchronously.  We tend towards that pattern even when
we know that execution will be synchronous, because we also that it
could be asynchronous one day.  Yes, we could wrap that up in a neat
bundle, but explicit is better than implicit.

Dan



More information about the Python-list mailing list