Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sun-barr!apple!bionet!arisia!roo!lanning From: lanning@parc.xerox.com (Stan Lanning) Newsgroups: comp.lang.c++ Subject: Re: Recommended book for C programmer learning C++ Message-ID: Date: 16 Nov 90 23:42:28 GMT References: <1148@teslab.lab.OZ> <1155@teslab.lab.OZ> Sender: news@parc.xerox.com Organization: Xerox PARC, Palo Alto, CA Lines: 94 In-reply-to: andrew@teslab.lab.OZ's message of 15 Nov 90 06:27:37 GMT I found Lippman's book to be, well, less then acceptable. It may help you learn the language, but it fails when it comes to illustrating programming. As the author says in the preface, "...the book is organized around a series of extended examples." While the examples may serve the immediate goal of illustrating a particular topic, they often show a concern for micro-optimization and a disregard for other issues. Experienced programmers will find these examples disturbing; novice programmers could come away with a misunderstanding of the art of programming. I would hope that a book would use examples of _good programming_ that illustrate the desired aspects of the language. This book doesn't satisfy that desire. Here are some examples: ----- Section 2.13, page 87. This section uses as an example "a member function to return the minimum value contained in an IntArray class object." The function works by walking through the array, storing the minimum value found so far in the variable minVal. He raises the question: what should the initial value of this variable be? He states "One approach is to initialize minVal with the largest possible integer value... this will work in every case. It is not, however, the best strategy." He then digresses into an analysis of different possible cases, and concludes "In *all* cases, by making minVal's initial value the first element of the array, we are guaranteed to save one assignment. In addition, only n-1 elements need to be examined." He does not mention that this method is easier to understand, or that there might be some difficulty in computing the largest possible integer value, or that this approach is applicable in situations where there is no largest possible value. The only reason given is the saving of a single assignment. ----- Section 3.2, page 107. Discussing inline functions, the author states: A question not as yet addressed directly is why min() was defined as a function. To reduce the amount of code duplication is not the reason. It actually requires one more character to write min(i, j); then to write the function directly: i < j ? i : j; He then goes on to mention five reasons why using min() is a good idea. He does not mention that open-coding requires computing an argument twice. Apparently this is not as important as a discussion of the number of characters required to type the expression. ----- Section 4.2, page 149. This page contains the following implementation of the function concat() that can be used to concatenate two linked lists of integers: void IntList::concat( IntList& il ) { // append il.list to invoking list object IntItem *pt = il.list; while ( pt ) { append( pt->val ); pt = pt->next; } } How is append() defined? From page 144: IntList::append( int val ) {// add to the back of the list IntItem *pt = new IntItem( val ); if ( list == 0 ) list = pt; else (atEnd())->next = pt; return val; } How is atEnd() defined? It walks down the list, and returns the last IntItem in the list. This is order N in the length of the list. It gets called once for each call to append(), which is called once for each element of the second argument to concat(). Thus, this implementation of concat() is order N^2. ----- -- -- smL