August 4th, 2009, 9:12 pm
QuoteOriginally posted by: AlexesDadAll that you get for free. Indeed you have used the release statement, but you have done so implicitly. This piggy-backing on the back of a destructor of a local variable should not be thought of as a 'trick' but instead as an example of 'working with the language instead of against it'Absolutely.And as to the applicability of Mark Joshi's "never use delete" guideline I would say that most quants are in the business of writing C++ libraries. Maybe some applications in C++ above those libraries as well, although Java/C# are often better choices for that layer nowadays. But the production of robust libraries is key to the role of a quant, and by *far* the best way to write C++ libraries that manage resources in a robust fashion in the presence of exceptions is to (in general) tie the lifetime of resources to the lifetime of controlling objects, and (in particular) to tie the lifetime of memory to smart pointers.Personally, when I have been sorting out problematic C++ library code in the past, I've found that a great initial thing to look for is explicit "delete" statements, as they are a very good indicator that the perpetrator doesn't really know what they are doing - so the surrounding code is likely to be problematic in several other ways.That is not to say we can't all make up instances where "delete" is the right thing to do, just to say that such times are in practice rare to the point of non-existence. None of this should be at all controversial. Bjarne Stroustrup has had detailed guidelines on how to write exception-compatible library code out on the web for free for at least 8 years, google for "C++ appendix e".On the other hand I think Herb Sutter made a right pig's ear of explaining about exceptions, massively over-complicating things - perhaps that is why so many people still seem to be confused about it.But if I am checking out someone's C++, I use some idea of how to manage resources robustly as part of an initial sheep-from-goats screen. If you can't sort that stuff out then frankly I don't care how good your stochastic calculus is, since you won't be able to realise your ideas in a form that other people will be able to use.