Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c++ > #15314
| From | Rui Maciel <rui.maciel@gmail.com> |
|---|---|
| Newsgroups | comp.lang.c++ |
| Subject | Re: Terminology - RAII vs. Scope Guard vs...? |
| Date | 2012-04-12 02:27 +0100 |
| Organization | Aioe.org NNTP Server |
| Message-ID | <jm5b2q$ka$1@speranza.aioe.org> (permalink) |
| References | <2b96be9d-1925-4455-b6f9-12b2b15ebfad@x17g2000yqj.googlegroups.com> <2afef88f-f05f-4eb7-929b-fb587f674c68@er9g2000vbb.googlegroups.com> <9164b5b9-0424-4acf-9d2f-1344db90b3a7@w5g2000vbv.googlegroups.com> <jm4pi6$kav$1@speranza.aioe.org> <eb5359e9-10a2-419e-b96a-f6a8a44c51f0@v1g2000yqm.googlegroups.com> |
Noah Roberts wrote:
>> 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).
</quote>
> It's just a technique whereby you can achieve that.
>
>> Regarding your assertion that RAII is an "idiom rather than a
>> philosophy", it isn't very reasonable.
>
> 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
Back to comp.lang.c++ | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-10 13:47 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Joshua Maurice <joshuamaurice@gmail.com> - 2012-04-10 14:36 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-11 09:10 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Joshua Maurice <joshuamaurice@gmail.com> - 2012-04-11 12:28 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-11 13:29 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Rui Maciel <rui.maciel@gmail.com> - 2012-04-12 02:29 +0100
Re: Terminology - RAII vs. Scope Guard vs...? Joshua Maurice <joshuamaurice@gmail.com> - 2012-04-12 14:31 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-12 16:48 -0700
Re: Terminology - RAII vs. Scope Guard vs...? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-13 02:34 +0200
Re: Terminology - RAII vs. Scope Guard vs...? Miles Bader <miles@gnu.org> - 2012-04-13 10:57 +0900
Re: Terminology - RAII vs. Scope Guard vs...? "Alf P. Steinbach" <alf.p.steinbach+usenet@gmail.com> - 2012-04-13 09:52 +0200
Re: Terminology - RAII vs. Scope Guard vs...? Rui Maciel <rui.maciel@gmail.com> - 2012-04-13 10:48 +0100
Re: Terminology - RAII vs. Scope Guard vs...? Miles Bader <miles@gnu.org> - 2012-04-13 22:18 +0900
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-13 09:21 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Jorgen Grahn <grahn+nntp@snipabacken.se> - 2012-04-11 21:36 +0000
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-11 16:07 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Juha Nieminen <nospam@thanks.invalid> - 2012-04-12 06:10 +0000
Re: Terminology - RAII vs. Scope Guard vs...? Gareth Owen <gwowen@gmail.com> - 2012-04-12 18:18 +0100
Re: Terminology - RAII vs. Scope Guard vs...? Juha Nieminen <nospam@thanks.invalid> - 2012-04-13 04:52 +0000
Re: Terminology - RAII vs. Scope Guard vs...? Gareth Owen <gwowen@gmail.com> - 2012-04-13 06:59 +0100
Never using free() or realloc(). Destroying heaps. @Jeff-Relf.Me - 2012-04-13 00:55 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Rui Maciel <rui.maciel@gmail.com> - 2012-04-11 21:28 +0100
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-11 13:40 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Rui Maciel <rui.maciel@gmail.com> - 2012-04-12 02:27 +0100
Re: Terminology - RAII vs. Scope Guard vs...? scott@slp53.sl.home (Scott Lurndal) - 2012-04-12 17:25 +0000
Re: Terminology - RAII vs. Scope Guard vs...? Gareth Owen <gwowen@gmail.com> - 2012-04-12 19:21 +0100
Re: Terminology - RAII vs. Scope Guard vs...? Noah Roberts <roberts.noah@gmail.com> - 2012-04-12 16:38 -0700
Re: Terminology - RAII vs. Scope Guard vs...? Rui Maciel <rui.maciel@gmail.com> - 2012-04-13 11:02 +0100
Re: Terminology - RAII vs. Scope Guard vs...? nick_keighley_nospam@hotmail.com - 2012-04-13 00:29 -0700
Re: Terminology - RAII vs. Scope Guard vs...? nick_keighley_nospam@hotmail.com - 2012-04-13 00:14 -0700
csiph-web