Home Page -------------------
[Home Page] - [Reviews Main]
-------------------

Book Review
Teach Yourself C++ 3ed by Herbert Schildt
Not Recommended
ISBN: 0 07 882392 7       Publisher: McGraw-Hill       Pages: 746pp       Price: £22-99
Categories:   beginner's c++    
Reviewed by Francis Glassborow in C Vu 10-2 (Jan 1998)
Herbert Schildt has worked very hard on this book. He has taken on board many of the criticisms that have been thrown at him for his early books as well as the earlier editions of this one. His main() religiously returns an int. His header files follow the new C++ form so we have #include <iostream> instead of #include <iostream.h>. We even have #include <cstdio> instead of #include <stdio.h>. In his dedication he thanks four people for sharing their knowledge, advice and expertise. I guess it is the only time that Al Stevens will share credit with Bjarne Stroustrup, Steve Clamage and P J Plauger (Al almost caused apoplexy among the members of J16 with a couple of his recent columns in Dr Dobbs Journal.) After a quick overview of C++ Schildt dives into the mysteries of writing classes in chapter 2. So you can guess that the first problem is that the book assumes you already know C. You would be right.

To exhibit the second problem I am going to quote verbatim from pages 220 and 221 where he provides an assignment operator for a string class he dabbles with by way of an example of a class. The class has two data members p which is a char * to handle a dynamic array to hold the string and len which holds the current capacity of the string object. Now read on:

strtype & strtype::operator=(strtype &ob){
// see if more memory is needed
if (len > ob.len) {
// need to allocate more memory
	delete [] p;
	p = new char[ob.len];
	if(!p) {
		cout << "Allocation error\n";
		exit(1);
	}
}
len = ob.len;
strcpy(p, ob.p);
return *this;
}
When you have recovered from the shock of reading this take a deep breath and read his commentary:

As you can see, the overloaded assignment operator prevents p from being overwritten. It first checks to see if the object on the left has allocated enough memory to hold the string that is being assigned to it. If it hasn't, that memory is freed and another portion is allocated. Then the string is copied to that memory and the length is copied into len.

Notice two other important features about the operator=() function. First, it takes a reference parameter. This prevents a copy of the object on the right side of the assignment from being made. As you know from previous chapters, when a copy of an object is made when passed to a function, that copy is destroyed when the function terminates. In this case, destroying the copy would call the destructor function, which would free p.

However this is the same p still needed by the object used as an argument. Using a reference parameter prevents this problem.

The second important feature of the operator=() function is that it returns a reference, not an object. The reason for this is the same as the reason ituses a reference parameter. When a function returns an object, a temporary object is created that is destroyed after the return is complete. However, this means that the temporary object's destructor will be called, causing p to be freed, but p (and the memory it points to) is still needed by the object being assigned a value. Therefore, by returning a reference, you prevent a temporary object being created.

I find it impossible to believe that anyone who has the slightest idea how C++ works could write the above. The source code would be an excellent student exercise in detecting serious flaws. The commentary is at best confused. The writer seems to have no idea that any class that needs a copy assignment also needs a copy constructor. He completely ignores the self-assignment problem. He does not seem to know that new throws an exception if there is an allocation failure. Even if he is writing code for a new(nothrow) self respecting C++ programmers do not call exit() and certainly do not do so in a function such as this one. There are also some deep problems such as his use of a reference parameter when a const reference will cause fewer surprises.

I wanted to like this book if not least because the author seems to have responded to earlier criticism but in reality it is clearly superficial and despite his dedication he has learnt very little from the experts he credits. I suppose I could have expected nothing more from an author who allows his publisher to place in large (extra large for the author's name) bold type the statement:

When you need solid answers, fast, turn to Herbert Schildt, the recognized authority on programming. Sorry, but he is not recognised as an expert by me nor by any C or C++ expert that I know. It would do him an immense amount of good to humbly read Bjarne Stroustrup's The C++ Programming Language , the third edition for preference, but any one would improve his programming. I would not expect an experienced C programmer to perpetrate this kind of C++ after a one-week conversion course from a competent trainer.


Other Authors with the same surname

Schildt
ANSI C Made Easy by Herbert Schildt  (Reviewed Nov 1990)
Annotated ANSI C Standard. Annotated, The by H Schildt [Not Recommended]  (Reviewed Sep 1994)
Art of C, The by Herbert Schildt  (Reviewed Mar 1992)
Born to Code in C by Herbert Schildt  (Reviewed Jan 1991)
C++ Nuts & Bolts for Experienced Programmers by Herbert Schildt  (Reviewed Sep 1996)
C++ The Complete Reference (2nd ed) by Herbert Schildt [Not Recommended]  (Reviewed Mar 1996)
C++ The Pocket Reference by H Schildt [Not Recommended]  (Reviewed May 1993)
C++ from the Ground Up (2nd ed) by Herbert Schildt [Not Recommended]  (Reviewed Mar 1998)
C++ from the Ground Up by Herbert Schildt  (Reviewed Mar 1995)
C++ from the Ground Up by Herbert Schildt [Not Recommended]  (Reviewed Sep 1998)
C/C++ Programmer's Reference 2ed. by Herbert Schildt  (Reviewed Sep 2000)
C/C++ Programmer's Reference by Herbert Schildt  (Reviewed Sep 1997)
C/C++ Programmer's Reference by Herbert Schildt [Not Recommended]  (Reviewed Jan 1998)
C: The Complete Reference (3rd ed) by Herbert Schildt  (Reviewed Nov 1995)
C: The Complete Reference 4ed by Herbert Schildt  (Reviewed Jul 2000)
Craft of C, The by Herbert Schildt  (Reviewed Sep 1993)
Expert C++ by Herbert Schildt [Not Recommended]  (Reviewed Sep 1998)
Java Programmers Reference by Joe O'Neil & Herbert Schildt [Not Recommended]  (Reviewed Mar 1998)
MFC Programming from the GROUND UP 2nd Ed by Herbert Schildt [Not Recommended]  (Reviewed Jul 1999)
STL Programming from the Ground Up by Herbert Schildt [Not Recommended]  (Reviewed Jan 2000)
Teach Yourself C (2nd ed) by Herbert Schildt  (Reviewed Nov 1994)
Turbo C/C++: The Complete Reference by H Schildt  (Reviewed Jan 1993)
Using Turbo C++ by Herbert Schildt [Not Recommended]  (Reviewed Mar 1991)
Windows 95 Programming in C and C++ by Herbert Schildt  (Reviewed Jul 1996)
Windows NT 4 Programming from the Ground Up by Herbert Schildt [Not Recommended]  (Reviewed May 1998)


Last Update - 13 May 2001.

To link to this review, please use the URL: http://www.accu.org/bookreviews/public/reviews/t/t001453.htm

Copyright © The Association of C & C++ Users 1998-2000. All rights reserved.

Mirrored from http://www.accu.org/