November 30, 2006
Leandro Lucarella wrote:
> Sean Kelly escribió:
>>> I don't see why writing correct code is that complicated. And how do you address the problem of repeating error handling code and the lack of encapsulation of scope(success/failure)?
>> The lack of encapsulation doesn't bother me much, though now I see what you're getting at.  I do think that having:
>>     auto scope t = new Transaction();
>>     scope(failure) t.rollback();
>>     // commits if not rolled back on scope exit, alternately use
>>     scope(success) t.commit();
>> actually aids readability a bit, at the expense of some extra code.
> So you are against all RAII done in the C++ way, I guess...

Not at all, I use it all the time :-)  But I don't think the C++ method works well for situations like the above.  Andrei's original series of articles on scope guards actually used transactions as their primary example for when the C++ method falls apart, and I agree with his reasoning.  That said, part of his argument *was* because the C++ method for detecting in-flight exceptions isn't very reliable.  Providing a fixed version in D would allow for both methods to be used--it's just a matter of making the necessary changes.  All of which could be done in phobos/internal, by the way.

Next ›   Last »
1 2