Negative

Walter Bright newshound at digitalmars.com
Wed Mar 1 12:02:32 PST 2006


"Sean Kelly" <sean at f4.ca> wrote in message 
news:du4mfe$18k5$1 at digitaldaemon.com...
> Walter Bright wrote:
>> RAII is for managing resources, which is different from managing state or 
>> transactions. try-catch is still needed, as on_scope doesn't catch 
>> exceptions. It's try-finally that becomes redundant, though it is useful 
>> to keep it because so many people are used to it.
>
> That may have been the original intent, but RAII has since become almost 
> indispensable for writing exception-safe code, be it with resources, 
> transactions, or something else.

RAII is used for those other things in C++ because there is *no other 
choice*. Nevertheless, the reality of using destructors to manage 
transaction processing is:

1) it's so hard to do that most programmers simply ignore the problem, 
trusting to luck that exceptions won't happen

2) those that do try it, most of the time get it wrong

3) it's pretty hard to visually inspect the code and determine that it is 
exception safe

This suggests to me that RAII and try-finally are the wrong paradigms for 
doing transaction programming. I've attended Scott Meyer's insightful 
lecture on doing transaction programming in C++. There is no hope for it to 
be reliably done by anyone but experts.


> Personally, I've never liked try-finally, but I attribute that to my C++ 
> background.  If I were a Java person it may be a different story.

Try-finally and RAII are like goto's. They work, but aren't using whiles, 
fors, switches, etc., much more natural? 





More information about the Digitalmars-d mailing list