Top positive review
51 people found this helpful
An excellent book for the complete novice
on July 7, 2011
C++ Without Fear, 2nd Ed
In the interests of full disclosure, I was provided a free copy of this book for review purposes. I am an experienced C++ programmer, and responded to a request (in a professional forum) for reviewers.
As a quick overview - an excellent first book for a complete programming novice; probably a little slow-paced for someone who knows other languages. The style and approach are well structured for the intended audience and there are few errors in the example code. It will provide you with a good grounding in the basics of C++, and no more - but that's its stated goal. You need to follow on with books such as "Effective C++" by Scott Myers, "OOAD with Applications" by Grady Booch, and some more advanced C++ books. This book (sensibly) declares templates to be an "advanced" issue and beyond its scope, so you'll need to look elsewhere for that information.
It is important to note the author's intended audience - namely someone whose computing knowledge goes little farther than "how to turn on a computer and use a mouse" (xxiii). This needs to be born in mind if you actually do know your way around a programming language. The approach to presenting technical concepts, and the level of technical language used, is well tailored to beginners - but will drive an experienced programmer to quickly look for another book.
Overall, this is an excellent first book for the pure novice. I would advise a true newcomer to ensure they read everything, including (even especially) the "optional" parts. The Preface (which potential engineers will be inclined to skip on instinct, smacking too much of reading the instructions) contains important information about the structure of the book, and where to find some of the essential tools. Overland describes his sidebars as "interludes", or digressions, but there is much important information buried in them. The appendices are also required reading!
One nice aspect is that Overland never uses a language feature he has not introduced, and never introduces a feature he does not immediately use in an example. And, rare nowadays for a book so loaded with examples, nearly all of the presented code will compile and execute as expected. An unfortunate side effect of this approach, however, is the the person wanting to learn C++ ends up knowing a lot about the C string library (perhaps it is simpler to introduce than, say, <strstream> and strings oddly form a key component of most simple examples). Another example of using the 'C' approach in a C++ book is the use of the preprocessor for defining constants, when C++ has a perfectly good alternative with const - i.e. on page 225 you should use
const int SCR_LINES = 25;
#define SCR_LINES 25
Many language features come with "gotchas" if they are misused or abused, and Overland generally makes sure to introduce the warts when he provides a new feature. One area he missed is with the "sizeof()" operator. The reader is not told that taking the size of an array gives the total size, and not the number of elements. This is a common misconception, usually arising because the first time "sizeof()" is met is with char arrays. Just to clarify, the sizeof() operator provides the number of chars (usually bytes) needed to hold an instance of its parameter thus for the following:
sizeof(charArray) equals 4, but sizeof(intArray) equals "4 * sizeof(int)". To get the "length" of an array, you need "sizeof(intArray) / sizeof(intArray)".
I think that Chapter 8 (on files) would have been simpler to present if the string class has been introduced first. Also, the examples dealing with binary, read-write, files have an error and a trap for new programmers. When writing the data to the file, the size is given as "sizeof(name) -1" which fails to write out the 20th character of the "name" - this happens to be the NUL character terminating a full size string - which causes problems in later examples when the file is read back and printed out. Also, this example allows a file to be created with empty records and then these empty records to be read back in with no validation.
Importantly, Overland devotes an entire chapter to the whole concept of pointers. These are fundamental to programming in most modern languages, and often one of the hardest things to come to grips with for complete novices. The explanation is clear and concise, and most readers should be left with a reasonable understanding of them. However, I think references could have been introduced a lot earlier in function prototypes - which would have obviated the need to deal with them quite so early on in the book.
While templates are sensibly put off for more advanced books, only providing enough information to begin using the STL, the section on exceptions really needs more detail. While a novice programmer may not choose to use them in their own designs, almost any library they link to runs a high chance of being able to throw exceptions. Thus, the novice is gong to end up being intimately acquainted with exceptions whether they like it or not.
In case you're thinking I don't like this book, don't get me wrong. I'll repeat that I think it is an excellent starter for the complete novice. But if you're wondering whether or not to buy it, you really want to know it's problems as well as its strengths. So I'll wrap up with a list of my personal grievances - there is also an errata available on the web which I recommend you download and use to mark up the book. the following are not in the errata (yet).
- An exercise on page 203 suggests the following to check if a (c style) string contains "@@@": "if (strcmp(input_line, "@@@")) ...". This should read "if (strcmp(input_line,"@@@") == 0)" as a non-zero return means "not equal to".
- The binary read/write example on pages 212, 214, 215, and 216 needs to remove the "-1" from the sizeof for the name field.
- Exercise 11.1.1 on p 296 talks about the "\=" operator, when it should be the "/=" operator.
- The array initialization on p329 declares arr_of_fract and then assigns 3 values, without explaining what happens to the 4th object.
- on p 371, the String class definition does not provide a type for the "ptr" member - should be "char *ptr;"
- Throughout the book, main() alternates between being defined as "void main()" and "int main()". Only the latter is correct. "Void main" harks back to the earliest K&R C language and has long been deprecated (or actually illegal) in C++.
- Virtual destructors are never explained, but their absence is a source of regular frustration in newbie's code.
- The book has a definite leaning towards the Windows world, with filenames containing "C:" for example.
- Many examples end with a call to "system("PAUSE");" to prevent the output console disappearing. They do not, however, include any headers to define "system()", and the "PAUSE" command is unique to Windows platforms. This was a source of frustration for my son when he tried to get his first example working.
- The compilers recommended in the preface are obsolete. There are much better free alternatives available today (for example: CODE::BLOCKS, Eclipse, Netbeans/C++) and this section needs to be updated.
- The biggest technical error I found in the book was on page 235, where Overland states that "variables are assumed to be private to the module in which they are created - unless and extern declaration is added". This is, in fact, completely the opposite of reality. In C and C++, the default linkage of a file-scope variable is GLOBAL, and the extern keyword just says "this is declared in another file".
These gripes aside (and there are always problems in technical texts!) it's a very good book, and I happily recommend it.