Order of constructor/destructor invocation

Geoff Gerrietts geoff at gerrietts.net
Tue Mar 5 15:08:33 EST 2002


Quoting Brett g Porter (BgPorter at NOartlogicSPAM.com):
> 
> As someone who needed a year or so to separate the C++ and Python halves of
> my brain, I sympathize, and can only urge (as gently as possible) Mr Charney
> to think Pythonically , instead of dealing with the frustration of expecting
> Python to follow C++'s rules. Down that path lies madness.

In particular here, I would point out that using constructors and
destructors to manage your implementation, while it seems elegant, is
really an incoherent design -- incoherent here meant in the technical
sense of "does not hold together", not the vernacular "intoxicated".

The constructor's purpose is to instantiate the object. The
destructor's purpose is to clean up when it goes away. Overloading
those methods with logic salient to neither purpose only serves to
make the methods unsuitable for generalized use.

In a tightly-constrained application, this might not be a problem, but
a solution that does not limit itself can work in more general
environments.

I think that's not only Pythonic, but OO.

--G.

-- 
Geoff Gerrietts             "If life were measured by accomplishments, 
<geoff at gerrietts net>     most of us would die in infancy." 
http://www.gerrietts.net/       --A.P. Gouthey




More information about the Python-list mailing list