Order of constructor/destructor invocation
Jeremy Bowers
newsfroups at jerf.org
Tue Mar 5 14:31:54 EST 2002
Reginald B. Charney wrote:
> In this idiom, I am not trying to traverse a tree. I am trying to execute
> what I declare. Also, this idiom allows for very shallow dependencies. There
> is no inheritance here. In this example, I am trying to write:
>
> h = HTML(); b = BODY(); p = PHP()
>
> Note that there is no interdependencies.
But there ARE interdepencies. If you didn't care about the order, you
wouldn't be upset about 'destructors' being called in the wrong order.
Thus, dependencies. You are trying to offload the order depencies onto
the destructor rules, but the destructor rules aren't hearing of it.
Additionally, the style you show is fundamentally too weak to work with
HTML.
h = HTML()
b = BODY()
l = LIST()
le = LISTELEMENT()
p = PARAGRAPH()
Is the paragraph a child of the list element, or not? This is merely one
of the hundreds of similar situations you'll encounter in HTML. You
can't generate HTML this way.
h = HTML()
he = HEADER()
t = TITLE()
b = BODY()
Now what? Will body be a child of title?
And again, HTML stands in for ANY tree structure. You ***cannot***
flatten a tree structure without losing data.
You have developed a style of coding that is *extremely* dependent,
dangerously so, on very, very particular details of a single,
increasingly outdated* language. Your style has numerous disadvantages,
and no significant advantages I can see. I echo the recommendations of
another poster to use a real HTML library, or to do something like what
I proposed, or, if nothing else, to simply declare HTMLStart and HTMLEnd
functions.
I don't know of any interpreted language that guarentees, as part of the
language specification, destructor order. For that matter, many
non-interpreted languages don't specify it either. In fact, even IF
C/C++ specifies the destructor order, which I don't care to look up
right now, I would not be surprised that not all compilers will destruct
in that order at the end of a function.
Perhaps you'd like functional?
HTML(BODY(PHP()))
No, it's not as simple as what you show, but that's life. It can be
adjusted to work better then that.
*outdated C: C/C++ has a well known set of advantages and disadvantages,
which I have no beef with. The point here is that nobody's trying to
make a better C nowadays. Unless you write your own, you may very well
NEVER find a language with destructors that are as user-controllable as
C. Most of us are happy to give up that responsibility, and concentrate
on writing code.
More information about the Python-list
mailing list