Noah said:
And just to entertain the idea that Joshua Maurice's claim was wrong,
then that would make Bjarne Stroustrup also wrong.[1] If you take the
time to read 14.4.1 from Stroustrup's "The C++ programming language" you
will realize that what's described there is essentially (or, arguably,
exactly) what Joshua Maurice just pointed out.
I don't have that book on my shelf at the moment and you don't even
bother to paraphrase so I have no idea if I disagree with Bjarne or
not.
He's not a God you know. All the big mucky mucks make mistakes. I
myself have corrected Myers on occasion.
He is not a God. He is the inventor of RAII, apparently. I believe we can
agree that the inventor of RAII should be expected to know a bit about RAII.
I very much doubt that Bjarne would claim that, "RAII is the way of
coding in which at every step of the program, if you have a resource
that needs to be freed, you can identify an object whose destructor
will free it, or the resource is an object on the stack"
You have the right to doubt that. Yet, if you happen to read "The Design
and Evolution of C++", by Stroustrup, you will read on section 16.5, the
section on RAII, that he states the following regarding RAII:
<quote>
Fortunately, there is a more elegant solution. The general form of the
problem looks like this:
void use()
{
// acquire resource 1
// ...
// acquire resource n
// use resource
// release resource n
// ...
// release resource 1
}
It is tipically important that resources are released in the reverse order
of their acquisition. This strongly resembles the behavior of local objects
created by constructors and destroyed by destructurs. Thus we can handle
such resource acquisition and release problems by a suitable use of objects
of classes with constructors and destructors.
<snip/>
I called this technique ''resource acquisition is initialization.''
</quote>
So, it may not be verbatim, but it sure is pretty much exactly what has been
said. If you disagree then read the above quote and also the one repeated
below, and do point out where these quotes don't agree.
<quote>
RAII is more than that. It's the way of coding in which you ensure
that all resources
1- have an owner whose destructor will free the resource, or
2- be on the stack (or a global or some other "root" of the ownership
tree).
It's just a technique whereby you can achieve that.
Well, it _is_ an idiom so if basing my statements on reality is not
very reasonable then I guess that's what I am.
The expression "programming idiom" refers to a particular way to express a
concept or idea which is specific to a particular language. RAII may have
been conceived by Stroustrup and described in a number of C++ books, but
that hardly makes it a programming idiom, let alone one which is exclusive
to C++. Any programming language which supports constructors/destructors
can implement the RAII technique, and even if the language doesn't support
constructors/destructors then you can always implement RAII by employing a
number of tricks in any programming language.
<snip/>
Rui Maciel