Re: C++ Speed Vs. Java
Gerhard Menzl wrote:
Ed Jensen wrote:
Deterministic destruction in Java isn't difficult. The pattern looks
something like this:
SomeType someType = null;
try {
someType = new SomeType();
// do some work
}
finally {
if (someType != null) {
someType.dispose();
someType = null;
}
}
I'll admit that it's less convenient than C++ objects created on the
stack:
{
SomeType someType;
// do some work
}
It's not just less convenient. It violates the time-honoured
principle "Once, and only once", and is therefore much more error-
prone and much less maintainable.
It's not just the idea of only writing it once. The problem is
that in many cases, the decision whether the class needs
deterministic destruction is made by the author of the class,
but must be implemented by the client. (Of course, this can
also be a problem in C++; if the object is allocated
dynamically, it's up to the user to invoke the explicit
destruction as well.)
--
James Kanze (Gabi Software) email: james.kanze@gmail.com
Conseils en informatique orient?e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S?mard, 78210 St.-Cyr-l'?cole, France, +33 (0)1 30 23 00 34
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]