On Mon, Jun 7, 2010 at 11:19 AM, Walter Bright <newshou...@digitalmars.com>wrote:
> Adam Ruppe wrote: > >> That sucks hard. I prefer it to finally{} though, since finally >> doesn't scale as well in code complexity (it'd do fine in this case, >> but not if there were nested transactions), but both suck compared to >> the scalable, beautiful, and *correct* elegance of D's scope guards. >> > > I agree. D's scope statement looks fairly innocuous and one can easily pass > it by with "blah, blah, another statement, blah, blah" but the more I use it > the more I realize it is a > > game changer > > in how one writes code. For example, here's the D1 implementation of > std.file.read: > > ------------------------------------------------------------- > ... > ---------------------------------------------------------- > > Note the complex logic to recover and unwind from errors (none of the > called functions throw exceptions), and the care with which this is > constructed to ensure everything is done properly. Contrast this with D2's > version written by Andrei: > > ... > The code is the same logic, but using scope it is dramatically simplified. > There's not a single control flow statement in it! Furthermore, it is > correct even if functions like CloseHandle throw exceptions. > Hmm, but I can actually understand your code. :-( --bb