



Review:Effective C++ CD-ROM 47
Effective C++ CD | |
author | Scott Meyers |
pages | |
publisher | Addison Wesley |
rating | 10 |
reviewer | SEGV |
ISBN | 0-201-60615-1 |
summary | More than the sum of its hardcopy contents, this electronic resource earns a place on the programmer's bookshelf. |
What to Expect?
I wasn't sure exactly what to expect. Subtitled "85 Specific Ways to Improve Your Programs and Designs," I knew this CD was an electronic version of Scott Meyers' already-published books, which I had previously reviewed for Slashdot:
So I knew a priori that the content was excellent, but how would it be packaged and presented? Would it be Windows-only, forcing me to use it only at work as I run Linux at home? Would it be awkward to read onscreen? Would it be easily searchable? Could I annotate and print portions of it?
A Pleasant Surprise
I was pleasantly surprised when the package contained only a CDROM with these instructions printed on it:
To start, open INDEX.HTM
System requirements: Netscape Navigator 4.0+ (on Unix, Mac, or Win32) or Microsoft Internet Explorer 4.0+ (on Win32 only).
So far so good! I had no problems using the CD with Communicator 4.5 on NT 4.0, and Communicator 4.04 on Debian GNU/Linux 2.0. Pretty much any modern browser with Java and JavaScript support should work. If you experience browser problems, the publisher provides helpful advice.
Initial Impressions
The CD has a nice look and feel to it. A navigation area is always present, acting as a control and providing a colour indication of where you are in the CD.
The text is decent to read and is true HTML, not merely raw text. It seems Meyers is conscious of the fact that an electronic version must add value to complement a printed version, otherwise it is not useful for its target audience.
Overall, I'd say this offering is a well though out and put together product, and not just a cheap knock-off.
Content
The CD (which itself has a printing number) contains the latest printings of the two books. It also boasts five magazine articles chosen by Meyers to augment the material in the books:
- "Exception Handling: A False Sense of Security" by Tom Cargill, from C++ Report Nov-Dec 1994.
- "Coping With Exceptions" by Jack W. Reeves, from C++ Report Mar 1996.
- "Exception-Safe Generic Containers" by Herb Sutter, from C++ Report Sep 1997, Nov-Dec 1997.
- "Counting Objects in C++" by Scott Meyers, from C/C++ Users Journal Apr 1998.
- "A First Look at C++ Program Analyzers" by Scott Meyers and Martin Klaus, from Dr. Dobb's Journal Feb 1997.
The first three are highly recommended for anyone dealing with exceptions. And of course, since any function may throw an exception, that means anyone writing C++! The object counting article elaborates on an idea from Effective C++ Item 14, illustrating some subtle language issues along the way. The final article outlines the state of the art in commercial static C++ analysis tools in September 1996.
Hyperlinks
The CD has links everywhere. Let me repeat: everywhere. In addition to hyperlinking existing references, Meyers added many cross references to the books and articles to further solidify the material.
Links to the internet at large are redirected through Addison Wesley Longman's online site so that they may stay current. And every single paragraph on the CD is anchored and hyperlinked, to facilitate electronic referencing and bookmarking.
Search Facilities
The CD provides two alternatives to your browser's "find in page" search facility. The first is a comprehensive merged index of the two books. The second is a search applet, modified from the Design Patterns CD search applet. It displays the resulting hits, with their enclosing paragraph for context if you select it. I found it easy to scan through hits until I found an interesting paragraph, then to jump to that document.
Although the search applet is aware of the entire CD, it appears that it can search only for one keyword. I'd really prefer more sophisticated search string options, such as multiple keywords, boolean operations, and perhaps even full regular expressions.
Configuration Facilities
For a set of web pages, the CD is impressively configurable. You can choose between five navigation area sizes, and five image sizes. You can view the books by item, by chapter, or in their entirety. And of course you can change text size in your browser.
Performance and Licensing
To implement the configurability options, there are actually five copies of each image and three copies of each book on the CD. Still, the total data size is a mere 16MB, which easily fits on a hard drive for greater performance and frees a CDROM drive for other use. This is also important because, given technology, actually altering the HTML files is really the only viable way of annotating the CD.
The CD comes with a single user license. You must contact the publisher for additional network license options. The short story is: you can make the CD available on a non-internet-accessible server to as many users as you have licenses, and you can purchase additional network licenses more cheaply the more you buy.
Summary
I've been using the CD both at work and at home for a couple of weeks, and I continue to find it a valuable resource. It easily subs in for my absent printed books, although of course I can't use it without a computer. The articles are useful, and the index and search applet allow me to quickly find what I am looking for.
Really, I have only three complaints:
- the search applet is somewhat limited
- there could be more magazine articles
- Scott's author photo is starting to look less like Eddie Van Halen and more like Gene Simmons
However, I don't think any of those detracts from the CD enough to reduce its 10/10 rating. In the worst case, since the CD is composed of text HTML files, you could apply other search utilities (eg, grep) to it.
The CD's online site has a demo, which I recommend trying if you want to get a feel for the CD before you purchase it. In addition to the general look and feel, navigation area, and search applet, it includes all of the magazine articles and a few of the books' items.
I'm happy with the CD, and recommend it as a professional resource.
To pick this up and help Slashdot, head over to Computer Literacy.
TABLE OF CONTENTS
Introduction
Effective C++ Second Edition
More Effective C++
Magazine Articles
Search the CD
efficcient C++ ...??? (Score:1)
cout } else {
cout }
efficcient C++ ...??? (Score:2)
eheh...
How Ironic (Score:1)
Good C book? (Score:2)
Having said that, I'd hate to live without Plauger's "The Standard C Library" and K&R II.
Take a look at the web-site version. (Score:1)
--
booch (no cookies at work)
How Ironic Not! (Score:1)
Common people OO exists for a reason and it is not consequential that many brilliant minds have written and expanded on OO (i.e. Design Patterns). If you don't like the technology then by all means shut up and go the way of the dinosaur. If you can't grasp it I feel for you, work harder, email me and I'll try to answer your questions if I can.
How Ironic (Score:1)
C++'s curse (Score:1)
"In true sound..." -Agents of Good Root
C++'s curse (Score:1)
C... the Universal Machine Language. (Score:1)
I can see virtues in Eiffel, Ada95, Java, etc., not the least of which is garbage collection. However, you'll probably find your pool of contributors is smaller with any of those except Java, and the performance issue still hasn't been quite worked out for Java. And I don't know that any of them are good for system-level programming, which you can do with C++.
Isn't the Linux source close to being compilable with the GNU C++ compiler?
Best argument for Java I've seen in a while (Score:1)
OS written in C++ (Score:1)
I don't think they would have chosen C++ if it produced bloated, inefficient code; the OS runs on palmtop computers with strict processing and memory limitations.
You just have to know how to use the language, that's all!
How I figure differently (Score:1)
1) C++ reduces programmer efficiency by being hard to read/understand. Proof: Look at the number of C++ projects that founder for lack of contributions.
Your proof is not. I'm sure you can find numerous C projects that failed from a lack of contributions.
C++ is not harder to understand than any other language that you already understand. In fact, learning C++ is the best way to become a better C programmer. The languages constructs in C++ are well designed and teach you a means to structure a program even in their absence.
With capacity to use overloaded operators and type conversions, you can make code that is fundamentally more readable than with a C program. For example, the STL (often considered strange looking by those who have only glanced at it) has a standard syntax for iterating over the members of a container (lets say the type is Container):
Container c; ....
for ( Container::iterator iter = c.begin ( ); iter != c.end; ++ iter ) iter->value;
This will work whether the container is a vector, list, stack, map (associative list), set (indexed list).
In C, there would be separate functions for each type of collection (and conversions for the generic pointer). But the best part is that the semantics mimic efficient iteration of a C array.
struct s[20]; ....
for ( struct s *iter = s; iter != s + 20; ++ iter ) s->value;
In the case of the vector container, that is the typical implementation.
Given that C++ can mimic C semantics while encapsulating more complex behavior makes the language easier to read than an equivalent C project.
2) C++ reduces program efficiency by being hard (if not impossible) to compile into an efficient executable. Proof: OS's and other high-performance programs are written in C.
This is one of those statements that is never backed up with fact. Some people seem to think that the size and speed of your program is proportional to the number of keywords in the language.
Given that C++ is a superset of C (with the semantics of struct being slightly different). There is no reason that a C++ compiler will implicitely produce inferior code.
When is not often stated is that the keyword in C++ can produce better code given the opportunity.
I will review two language features that are often accused of causing inefficiency: dynamically bound functions, and exception handling.
The key thing to remember is that to reproduce the equivalent behavior is C for using these features the only difference is that you are writing the code yourself. In every case, the compiler would have done a better job itself.
Virtual function are often implemented as a virtual table of function calls. This means that a virtual function call requires a table index before the function call. This is one more instruction (some processors do this for you) in a function call that may be hundreds -- before you even get to the function.
The equivalent switch statement introduces a lot more code because it has to compare against all of the values. If you get fancy and make a similar lookup table ... why didn't you just let the compiler do that for in the first place?
The estimate for exceptions is often estimated at a 5-10% overhead:
"This is huge." the C programmers cry.
But it's not so bad after you realize that your code if free from all of the error code checks. The ones where after every method call, you have to check whether it was successful before using the return value.
Freed of that burden, you can actaully use your return values. For example the C code:
Foo *pFoo = GetChickenFoo ( );
if ( pFoo != NULL ) pFoo->layLotsOfEggs ( );
If under C++, we define GetChickenFoo to return a valid pointer or throw an exception (give me foos or give me death!) we have:
GetChickenFoo ( )->layLotsOfEggs ( );
Which one would you rather write. Even better, this second code is more efficient because: there is no check (already done), there's no jump (pipelined processors hate those), and no early return (more code generated).
Over an entire project, you get your 5-10% back pretty quick (and possibly then some) all without you having to write more code.
There are more constructs like inlining, templates and (gasp!) template meta-programs (where you trick the compiler into generating the perfect source code for you depending on the context) which can improve code efficiency further.
For those who want to know how C++ can be used inefficiently, here are some things to look for: excessive duplicating of objects (through pass-by-value parameters and returns), excessive reallocations, excessive data type conversions, and the streams library (which has yet to have a fast implementation).
Trials and tribulations of search applet writing. (Score:1)
A security exception is raised when an applet attempts to open a file for read only RandomAccess (even if it is in a subdirectory of the directory that the applet resides in). You can only open a file for sequential access. This sucks, badly.
A way around this would be to open a file for sequential access and use the skipBytes method to mimic RandomAccess this works and is fast on IE but is DEAD SLOW under netscape.
That search Applet... (Score:1)
Is this the sign of things to come - a truly cross-platform interactive book-on-CD that is not platform dependent?
Seems like a good use of Java technology to me - interactive publishing...
Best argument for Java I've seen in a while (Score:1)
how do you handle 'instantiation is allocation', i.e., having the constructor of a stack-allocated
object grab a resource, and the destructor deallocate it when it goes out of scope?
routine in C++, impossible in Java, but highly desirable nonetheless.
Best argument for Java I've seen in a while (Score:1)
I think that one has still yet to be solved in Java.
REVIEWER Comments on Language Wars (Score:1)
Second, if you are going to offer your comments, perhaps you should offer your credentials.
I am a professional software developer. I've been in the industry for several years and have worked on shipping products.
There is a major difference between a homework assignment or tic-tac-toe program, and large-scale projects.
C, C++, and Java all have their place. I myself had a Java renaissance for awhile, but have come to recognize that it doesn't come close to C++ in many ways. Since then, I've learned more about C++ and come to appreciate it more.
In my experience, if Java code is better than C++ code, it is because it is *newer* code and the people writing it know better what they are doing these days, than when they wrote C++ code a few years earlier.
In my experience, people are hard on C++ because it is not a trivial language to pick up. Not all of my co-workers understand the code they are working on. That will always be true to some extent, but I believe it is more of a deficiency in skill than a language deficiency.
In my experience, C++ has advantages over C that make it preferable. I can bundle concepts up into types, express idioms (dynamic binding, error handling, etc.) at the language level, and have better type checking.
In my experience, people have problems with C++ because they haven't applied themselves to its study. As with any language, you have to read more than the "primer" to be proficient at it, to not get into trouble, and to know when you are getting into trouble. Otherwise you remain blissfully ignorant.
C++ is more complex because it was designed for more complex tasks. How many have read "The Design and Evolution of C++?" How many have read "The C++ Programming Language?"
You can argue that you should be shielded from that complexity, but there remain programmers who have to face it, even if you don't. So pick your language and put your code where your mouth is, and leave the C++ coders to do the same.
Badmouthing C++ (Score:1)
I want to release under LGPL a C++ communications transport library based on the UNIX pipes concept that I've spent a lot of time developing, but I'm worried about the response of the OSS community. It would be highly disappointing to release it and have it fall flat.
This library could only have reasonably been written in an OO language. The only OO language with the speed I want, the type safety I want, and the access to low level OS facilities that I want is C++.
Some of the posts to this group are not very encouraging, and some are. Does anybody have any suggestions or advice? And no, it CAN'T be ported to C. I might consider a Java port, but that would co-exist with the C++ library, not replace it.
Here's 2 (Good C book?) (Score:1)
Practical C Programming (Nutshell) by Steve Oualline and Andy Oram. 480 pages and $27 on Amazon.
Well put, but I couple points. (Score:1)
And yes I've found him to be an excellent source of design knowledge, as well as the GoF and Three Amigos.
Shouldn't be surprising as his area of study is large-scale systems.
How I figure differently (Score:1)
> for ( struct s *iter = s; iter != s + 20; ++ iter ) s->value;
You know you cannot do that in C, don't you?
C++'s curse (Score:1)
Contrary to the above statement, C++ was in fact very well thought out. If you feel differently, I suggest reading The Design and Evolution of C++.
Given the set of design goals Stroustroup sought to meet and the tradeoffs he needed to consider in designing c++, I would say he did a very good job.
As for Dylan, Smalltalk, Eiffel, Java, etc, a major issue to take into consideration is that none of these were designed with backward compatibility to C as a constraint. Freedom from this is part of what makes Java a "safer" language to program in.
Someone else mentioned that C++ is like multiple languages wrapped up into one. Well...it is. As I understand, Stroustroup seems to believe that programming need not follow only one paradigm. C++ supports multiple forms of programming, including Abstract Data Types, Object Oriented Programming (there's a difference between the two!), and Generic Programming (through templates). And that's not to mention C, which is also encapsulated in C++ (remember, every program in Kernighan and Ritchie is a C++ program).
Even when I program in C-style, I still tend to program in C++ insofar as I use c++ style comments and I prefer to declare variables close to where they are used (given a large program, this increases my comprehension). Not to mention I prefer C++ strong typing to ensure my code uses the correct parameters.
OS written in C++ (Score:1)
Hmm... just one thing: with a LOT of code, whether you use pointers or references, it produces EXACTLY the same assembly code... interesting, hmm?
OS written in C++ (Score:1)
Well they are needed for overloading operators, like operator +.
overloaded operators should do what they were originally meant to do
Um, I don't quite follow you here. Are you advocating completely avoiding operator overloading? I hate having to write crap like ((Integer)(myVector.elementAt[i])).intValue() in Java where as in C++ I can simply write myVector[i] (well part of the problem is that Java doesn't have templates). Anyway the point is that operator overloading as used in the STL makes it possible to write much more readable code.
the standard c++ library is a horrible kludge and an example of bad code
Well I thought the STL is a library specification rather than an implementation, so it doesn't make sense to call it bad code. Do you think it is designed badly? I know it bloats my code horribly but I'm kinda hoping that's because C++ compilers are still immature.
How I figure differently (Score:1)
> char data[20];
> for ( char* iter = data; iter != data+20; ++iter )
>;
You obviously don't know C.
You can't declare a variable in the for arguments. Declarations must come before statements.
REVIEWER on Search Applet (Score:1)
I see now that it does search for more than one term, but for some unknown reason it may only highlight one in the search results. That was why I was confused and thought it only searched for one term, an especially easy mistake to make if the other term is elsewhere in the paragraph.
It also takes wildcards, although not regular expressions. I'm not as convinced now that regular expressions are really necessary for the search applet to be useful. However, it would be nice to have AND, OR, NOT, etc.
In summary, I'm happier with the search applet now and glad that I didn't dock a point off the CD because of my perceived shortcomings with it.
religious war (Score:1)
If you want to play with the best of machinery for a couple of decades and get paid big bucks for it, you learn and use whatever best suits the problems the real world provides to you.
Sometimes you need C++. I just ordered the CD. After all, it's just another computer program and using them gets me all sorts of neat toys.