[comp.lang.c++] Book of the Week Club

jimad@microsoft.UUCP (Jim ADCOCK) (11/29/90)

Just went down to my local bookstore and found a couple more new books
on C++.  One by Stevens on C++ and Fractals [actually, looks like its 
more on ray-tracing than anything] _might_ be of specialized interest to
people with a strong interest in both.

The other I picked up and am about half way through, and it seems good:

A C++ Toolkit
Jonathan S. Shapiro
Prentice Hall 1991
ISBN 0-13-127663-8

Shapiro's thesis is that one should make a bunch of small stand-alone
toolkit classes: Linked Lists, Hash Tables, Ref Counted Ptrs, etc, and
reuse them rather than gin up these common programming techniques on
the fly each time you need them.  Lots of practical suggetions.  Forest
rather than the tree approach.  Shapiro does the uncommon but nice thing of
explicitly allowing public use of the code in his book.

Be forwarned however that in his ref counted pointer class he makes the
common mistake of decrementing the old referenced object before incrementing
the new referenced object.  This has the effect of possibly prematurely 
deleting the old referenced object when it is the same object as the newly
referenced object.  Probably the best fix is just to explicitly test against
the possibility that the old and new objects are the same.

In any case, I like this book a lot and recommend it.  Examples include:
SimpleString, Point, Rectangle, Square, GeomObject, Point3d, Set256,
BitSet, Link, List, Array, BoundedArray, BinaryTree, HashTable, Pointer,
Ref Counted Ptr, Atoms.

zeil@cs.odu.edu (Steven J. Zeil) (11/30/90)

In article <59405@microsoft.UUCP> jimad@microsoft.UUCP (Jim ADCOCK) writes:
>Be forwarned however that in his ref counted pointer class he makes the
>common mistake of decrementing the old referenced object before incrementing
>the new referenced object.  This has the effect of possibly prematurely 
>deleting the old referenced object when it is the same object as the newly
>referenced object.  Probably the best fix is just to explicitly test against
>the possibility that the old and new objects are the same.

Actually, that fixes only a special case of the general problem.
Suppose that A points to B, B points to C, and I try to replace the
pointer in A to make it point to C. This passes your proposed test,
but decrementing B's count before incrementing C's could result in
both B and C being deleted, when in fact only B should have been
deleted.

                                                            Steve Z