JPEG Thumbnailer
Ingo Klöcker
kloecker at kde.org
Tue Aug 19 22:41:24 BST 2008
On Tuesday 19 August 2008, Richard Moore wrote:
> On 8/19/08, Ingo Klöcker <kloecker at kde.org> wrote:
> > I know you will kill me for making the following suggestion. :-)
>
> Various phrases around using a hammer to crack a nut spring to mind.
> In the context of the question this strikes me as a rather foolish
> idea.
Indeed. Writing an error prone implementation where you have to make
sure you do not forget to call fclose() in any of the various code
paths (the code is question has to call fclose() in two different code
paths) is comparable to using a hammer to crack a nut. OTOH, using a
smart pointer with custom deleter is like using a high quality nut
cracker to crack a nut, because a smart pointer with custom deleter is
exactly the right tool for dealing with a FILE* resource.
Please allow me to quote from C++ Coding Standards [1] by Herb Sutter
and Andrei Alexandrescu (a book any serious C++ developer should read
and take by heart IMHO):
<quote>
Item 13: Ensure resources are owned by objects. Use explicit RAII and
smart pointers.
Summary
Don't saw by hand when you have power tools: C++'s "resource acquisition
is initialization" (RAII) idiom is _the_ power tool for correct
resource handling. [...]
Discussion
C++'s language-enforced constructor/destructor symmetry mirrors the
symmetry inherent in resource acquire/release function pairs such as
fopen/fclose, [...].
</quote>
Regards,
Ingo
[1]
http://www.bookzilla.org/shop/action/productDetails/3266781/herb_sutter_andrei_alexandrescu_c_coding_standards_0321113586.html
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 194 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.kde.org/pipermail/kde-core-devel/attachments/20080819/029047b5/attachment.sig>
More information about the kde-core-devel
mailing list