in reply to Re^4: Execution order of END/CHECK vs BEGIN/INIT (exit??)
in thread Execution order of END/CHECK vs BEGIN/INIT
Perhaps Tilly was thinking of POSIX::_exit which was muted (by me, though previously by another) but as a possibly workaround to a different problem.
On package constructors/destructors point, I realise the nature of the beast, and if you accept that such implicit destructors are a 'Good Thing', then I agree that there is some merit in their being called in LIFO order between the packages. Clumbsily stated, but I mean that the END blocks of the first encountered package (generally main) should be called last. Those of the second package encountered--generally the first use statement within main--should be called second from last. Those of the third package encountered--perhaps the first use statement within the first package called from main--being called third from last. And so on through the package hierachy.
But I still find it counter-intuative that the END blocks within any given package will be called in the reverse of their physical ordering in the code, and even worse, that I would have to place the END block(s) in my code, be it main or package, before any use statements in that same package, in order to ensure that my code gets it's final opportunity to clean up after those subordinate packages it calls.
If I were sitting down to design the END block processing from scratch, I would combine the END blocks within a package in their natural ordering, and call these combined destructors in the LIFO order of which the packages came into existance. That's probably too complex, but it seems like the 'right way' to do it to me.
Generally, I think that reliance on automatic destructors is a bad thing, and that every package should offer me a call that allows me to inform them when I have finished with them. The END block for that package could then test to see if I have done the right thing, and only call the destructor if I haven't.
At the end of the day, my opposition to the current mechanism is purely academic as I have rarely ever used END blocks, and never in anger. And as Tilly pointed out, I've also never heard of anyone who has actually fallen foul of the problem I perceive, and so this is likely just (another) load of hot air on my behalf. That does lessen the strength of my feelings against the status quo though, and I would still consider it to be a bug. Or at least, consider any code that replied upon intimate knowledge of the order in which they called as a bug, because if one person can write code that relies upon this, then two can, and eventually the two pieces of code will come together, and there is no way to have both called last.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Re^4: Execution order of END/CHECK vs BEGIN/INIT (exit??)
by tilly (Archbishop) on Jun 30, 2003 at 16:34 UTC |