Board index » cppbuilder » Re: try/finally

Re: try/finally


2005-12-09 06:34:41 PM
cppbuilder49
Thomas Maeder [TeamB] wrote:
Quote
Tom Widmer < XXXX@XXXXX.COM >writes:


>class RAII
>{
>public:
>RAII(function<void()>const& f) :m_f(f){}
>~RAII() {f();}


(this->m_f)();
Actually, thinking about it (which I clearly didn't do before!), it
should be:
if (m_f)
m_f();
Quote
Hmm. fclose() returns int.

Wait a minute - this works anyway! Astonishing!
Bind is very forgiving on signatures, discarding return types as required.
Quote
The reset() member seems essential to me. If the file were opened for
writing, one would do

raii.reset();
if (fclose(f))
; // error handling - file probably corrupt


at the end of the block and the fclose() invoked by raii would nicely
kick in if there is an exception.
Exactly.
Tom
 
 

Re:Re: try/finally

Rudy Velthuis [TeamB] wrote:
Quote
True. And yet, I feel that for one-off situations, writing a RAII
class is more work than using try-finally. <g>
From my years of experience writing C++ code, I find there are very few
one-off situations.
There might have been more overhead if the first 12 months or so,
before I understood so well, and before I had built our foundation
libraries.
I have not felt the need to reach for a __finally clause to avoid
writing a class for a few years now. Those situations simply don't
occur.
I think this is the difference between working with a large production
level C++ system, and playing around with small ->moderate sized
examples. Once you have the foundation in place, the support is simply
there in the library so these 'short cut' techniques like finally are
often more work than simply using what is in place.
It is probably the reason C++ is devolving into an 'experts' language
rather than a dabblers language. Producing (or learning) that
foundation is a significantly larger proportion of the time required
for the smaller tasks.
--
AlisdairM(TeamB)
 

Re:Re: try/finally

At 11:13:44, 10.12.2005, Alisdair Meredith[TeamB] wrote:
Quote
I have not felt the need to reach for a __finally clause to avoid
writing a class for a few years now. Those situations simply don't
occur.
Well, __finally is not standard C++ anyway, so that is not a surprise. <g>
--
Rudy.Velthuis {TeamB} velthuis.homepage.t-online.de/
"A clever man commits no minor blunders."
- Goethe (1749-1832)
 

{smallsort}

Re:Re: try/finally

On 10 Dec 2005 03:13:44 -0700, Alisdair Meredith[TeamB] wrote:
Quote
Once you have the foundation in place, the support is simply
there in the library so these 'short cut' techniques like finally are
often more work than simply using what is in place.
Also (I think) when you're working with large systems, addition tol
functionality (whether classes, functions -- you name it) will require
additions to the test base. Right there, the one-off is a "two-off".
--
liz
 

Re:Re: try/finally

Alisdair Meredith[TeamB] wrote:
Quote
I think this is the difference between working with a large production
level C++ system, and playing around with small ->moderate sized
examples. Once you have the foundation in place, the support is
simply there in the library so these 'short cut' techniques like
finally are often more work than simply using what is in place.
Yes. In our case our own code becomes the tool. We still write C++ but
it's mostly just 'glue' linking one or more objects or modules together.
--
Andrue Cope [TeamB]
[Bicester, Uk]
info.borland.com/newsgroups/guide.html
 

Re:Re: try/finally

Rudy Velthuis [TeamB] < XXXX@XXXXX.COM >wrote:
Quote
[...]
And no, I am not advocating sloppy programming.
See your sig:
Quote
"The average person thinks he isn't." -- Father Larry Lorenzoni
Schobi
--
XXXX@XXXXX.COM is never read
I'm Schobi at suespammers dot org
"If you put a large switch in some cave somewhere, with a sign
on it saying 'End-of-the-World Switch. PLEASE DO NOT TOUCH',
the paint wouldn't even have time to dry."
Terry Pratchett
 

Re:Re: try/finally

At 15:39:16, 12.12.2005, Hendrik Schober wrote:
Quote
See your sig:

>"The average person thinks he isn't." -- Father Larry Lorenzoni
Well? I guess that applies to all of us here. <g>
--
Rudy.Velthuis {TeamB} velthuis.homepage.t-online.de/
"In theory, there is no difference between theory and practice. But, in
practice, there is."
- Jan L.A. van de Snepscheut
 

Re:Re: try/finally

"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >writes:
Quote
>>"The average person thinks he isn't." -- Father Larry Lorenzoni

Well? I guess that applies to all of us here. <g>
I wonder why Liz didn't protest against this form of sexism? :-)
 

Re:Re: try/finally

At 21:03:17, 12.12.2005, Thomas Maeder [TeamB] wrote:
Quote
"Rudy Velthuis [TeamB]" < XXXX@XXXXX.COM >writes:

>>>"The average person thinks he isn't." -- Father Larry Lorenzoni
>
>Well? I guess that applies to all of us here. <g>

I wonder why Liz didn't protest against this form of sexism? :-)
LOL! That may come anytime now. <g>
--
Rudy.Velthuis {TeamB} velthuis.homepage.t-online.de/
"Any man who is under 30, and is not a liberal, has not heart; and any
man who is over 30, and is not a conservative, has no brains."
- Sir Winston Churchill (1874-1965)
 

Re:Re: try/finally

On Mon, 12 Dec 2005 21:03:17 +0100, Thomas Maeder [TeamB] wrote:
Quote
I wonder why Liz didn't protest against this form of sexism? :-)
Because I was out with the guys...
--
liz