Dr. Dobb's Journal May 2000
I've been "cyberslammed." (I'm not sure that's a word. If not, I'm coining it here.) To understand how this happened, you must know three things about how things work here at the Stevens house. First, I write the programs and columns and Judy collects and dispenses the money. Second, we have a complicated phone bill covering a voice line, a data line, two cell phones, and lots of long-distance calls. Third, we have a web page with links that generate small amounts of revenue. For example, if you link to amazon.com from my web site and buy a book, I get a commission check. Now, with all this insight into our business model, you will understand how I got cyberslammed and how it could happen to you, too.
Last summer I got a check in the mail for $3.50 from an ISP whom I shall call "cyberslammer.com." Assuming it was another of those link commission checks, Judy flipped it over, ignored the small print, wrote "for deposit only" on the back, and merrily drove it to the bank along with the other piles of money that came pouring in that week.
Last month, Judy found an appended billing on our phone bill that she hadn't noticed before. It was in the name of cyberslammer.com and charged $29.95 for "Internet Service." The phone company collects revenue for anyone who is authorized to charge things to your phone number; the appended billings are printed in the same format as the phone bill and they all look oh so official. A call to cyberslammer.com's customer service revealed that by cashing that check for $3.50, we had unwittingly subscribed to their Internet service. Research of Judy's records revealed that we had been paying that $29.95 bill every month since last summer. It's our fault, of course, for not reading the small print on that check and not screening the phone bill more carefully; we use the excuse that the complexity of the bill each month makes it inconvenient to do so and therefore easy for someone to hide charges. Just the kind of trusting folks that companies like cyberslammer.com lie in wait for.
Another call to cyberslammer.com's customer service and a connection to someone in management got us off the hook -- almost. When I objected to paying so much money to an ISP for service I did not know I had, never used, and would not want at that price -- dialup service is a lot cheaper around these parts -- they agreed to refund all but the first month's charge. I mounted a valiant argument to get back that last thirty bucks. The supervisor launched into a carefully rehearsed speech defending the company's policies and their right to do business that way and pointing the finger back at us for not taking notice of the terms and conditions for depositing a check. I responded that as a journalist in the computer industry with a finger on the pulse of the user community (yeah, right), I do not think many people would approve of their devious marketing practices. That's when I got the next level of prepared response, the one for the press. Obviously, they have been getting a lot of complaints.
I do not identify the company here because they reluctantly agreed to refund most of the money (the first month's charge was not refunded), and I do not want to get into a public debate about fairness -- one that might involve lawyers. I want only to alert you to a new kind of scam. The company showed no inclination to cease a practice that many consumers would find disagreeable and deceptive. And, of course, marketing strategies that work survive, ethical basis notwithstanding, which accounts for rampant uses of spam, slamming, junk phone calls, and the like. If they didn't work, companies would stop using them. So, two warnings for you readers: Don't cash an unexpected check without reading the fine print (unless Ed McMahon delivers it in person), and take a few minutes each month to read your phone bill. If we nip such scurrilous scams in the bud, they will go away.
We are often urged to use classes and functions from the Standard C++ library whenever possible. We are urged to gradually phase out our use of the legacy C++ library that survives from the old days and that compilers support to maintain compatibility with legacy programs.
There is a cost, however. Assuming a program does not require the standard libraries -- it does not use new features and does not link with third-party libraries that use standard libraries -- you can build it with either library. Yet it takes longer to compile and link that program with standard headers and libraries than it does to build the same program with legacy libraries. And the standard-conforming executable is significantly bigger. What does paying this cost buy us?
I noticed this behavior when building the executable programs for my C++ tutorial books. These books include the gcc-mingw32 compiler with Quincy 99, my IDE (http://www.midifitz.com/alstevens/ quincy99). An experimental standard library has been released for this platform (ftp://ftp.xraylith.wisc.edu/pub/khan/gnu-win32/mingw32/snapshots/) and I considered using it for the example programs. The first thing I observed was that it took a long time for gcc-mingw32 to compile and link even the simplest programs. The second thing I noticed was that the executables were much bigger. I did make sure that the experimental library is distributed without debug information, which would have added considerable size to the binaries. That was not the problem.
After seeing all this, I decided to stick with the old libraries for those programs that do not need the newer stuff (stringstreams and locales, for example). The gcc compiler emulates Standard C++ libraries when you use the old ones. You can include the new-style headers and use the std namespace qualifier, and the programs compile and link even though they are using the old stuff.
These performance and size observations made me wonder about other compilers. After all, the gcc standard library is still under development and all the optimizations might not be in place. I used a simple "Hello World" program to compare the performance of gcc with both libraries and VC++ 5.0 with both versions of its libraries. Examples 1 and 2 are the two programs. Table 1 shows the results of this simple benchmark on a P-300 under Windows 98.
There are several things to consider about these benchmarks. I performed each one following a reboot so that file caching would not contaminate the statistics. But file caches are one of our weapons against inefficient software, and perhaps they should be a part of any measurement that helps determine what platforms to use. Furthermore, the overhead imposed on the build of a trivial program might be insignificant when imposed on that of a nontrivial program. Better benchmarks might involve bigger programs and applications.
Perhaps we can ignore the behavior of gcc-mingw32 with its experimental Standard C++ library. (Although it's hard to ignore 20 seconds to build "Hello World.") But can we ignore the relative sizes of the two executable binaries produced by VC++ 5.0? You pay a big cost for using the standard library. Is it worth it? Are bigger executables a problem in these times of multigigabyte media? Given that many programs compile and execute just fine by using the legacy libraries, what motivates a project to make the change?
To me, a revealing comparison is the difference between the executable sizes produced by VC++, a commercially developed and marketed program, and those produced by gcc-mingw32 -- a freely available open-source program. It says something about how profit motivation might compel organizations to build more competitive products versus how communities of volunteers are motivated to put out something that only gets by in the performance comparison department. By the way, VC++'s Standard C++ Library is at least three years old. The gcc experimental library is still quite a way off from being viable for building real applications. Open-source advocates who cajole Microsoft to join the movement might do well to ponder these comparisons.
Speaking of free compilers, the Borland C++ compiler Version 5.5 with a Standard C++ library is available for you to download at no cost. The URL is http://www .borland.com/bcppbuilder/freecompiler/. I had hoped to download and report on it this month, but the download procedure does not work -- something about their server not liking my server. Several users of comp.lang.c++.moderated reported difficulties using the free compiler because of things that were left out of the distribution. They said that attempts to compile nontrivial applications failed. Inprise (Borland) will have to take these reports one at a time and upgrade its free distribution to plug the holes. It probably did not figure on having to provide support for what it is giving away. By the time Inprise has filled in all the missing parts, assuming it does, it just might have a free compiler that competes with the one it sells.
One of the missing pieces is a debugger. That's a major deficiency unless you remember the old days before CodeView and TurboDebugger when we debugged C programs on the PC by using printf statements to trace programs and watch variables. If Borland uses a standard format for debugging information other debuggers might work.
Another missing piece of information on the web site is the redistribution rights. If authors (like me) can include the free compiler with C++ books, we have an alternative to the gcc compiler that has been so long coming up with a Standard C++ library and is not nearly there yet.
If I am ever able to get a copy, I'll test it with the example programs in my C++ tutorial books. None of those programs can be considered nontrivial applications, but they do represent a near-comprehensive set of Standard C++ features put to use.
No, the heading to this paragraph is not a C++ expression. It's the name of several books from Addison-Wesley presented in a regular expression with a wild card. In 1992, Addison-Wesley published Scott Meyers' Effective C++, which enjoyed critical and commercial success and which I've mentioned before in this column. Since then Scott followed with More Effective C++ in 1996 and a second edition of Effective C++. Publishers often exploit the popularity of a book by putting out look-alike titles with look-alike covers. Here's how it works: If a publisher gets lucky with a title like "Paradigms for Parakeets," for example, you can bet that next season will have lots more titles of this and that "for Parakeets" to ride the wave.
Following that brilliant marketing principle, Addison-Wesley adds three titles to a new line seemingly inspired by Effective C++ that I will call "E* C++." These titles are Exceptional C++ by Herb Sutter, Essential C++ by Stanley Lippman, and Efficient C++ by Bulka and Mayhew.
Efficient C++ is about how to write efficient programs in Standard C++. This book is not as down and dirty as Michael Abrash's classic Zen of Code Optimization (1994, Coriolis Group Books), which uses assembly language optimizations to get closer to the metal and grind out that last elusive cycle. Nor does it provide a huge code optimization source-code resource such as Steve Heller's Optimizing C++ (1999, Prentice Hall). Instead, this book concentrates on the performance implications of common Standard C++ programming idioms, how to make them work more efficiently, or how to replace them with more efficient idioms. The authors discuss constructors and destructors, virtual functions, inlining, memory management, temporary objects, the STL, and other C++ features that are often abused even when they are understood. Code fragments rather than complete programs serve to illustrate the points. The book shows its authors' mettle when it gets into the finer points of design optimization. They get you thinking right when they say, "The obsession with reusable code has produced software that, due to the lack of efficiency, was not even usable, not to mention reusable... The problem is that performance and flexibility are often enemies." Well said.
Essential C++ is yet another C++ tutorial for programmers looking to learn the language. Lippman is the author of C++ Primer, also published by Addison-Wesley, which has, through several editions, grown as the language has grown to over 1200 pages. Essential C++, at 274 pages, is an effort by the author to reduce the information in C++ Primer to only those essential parts of C++ programming that a programmer needs to learn to become productive and to shorten the technique for presenting the material. I have only the first edition of C++ Primer from 1989 to compare, which, at 476 pages, is almost 200 pages longer than Essential C++. Lippman achieved his goals; in Essential C++ he successfully covers the core language as well as many features that were not available in 1989. At the same time his writing has improved from a ponderous, heavy-laden passive voice style of prose to a most readable and entertaining style of presentation. (Lippman also changed his code brace placement style, too, another improvement in my opinion.)
Exceptional C++ is the book I spent the most time with because it addresses experienced C++ programmers and encourages you to think about many aspects of C++ programming. Like Meyers' work, this book is grouped into Items -- independent essays about specific C++ programming practices and idioms. (Scott has 50 items in Effective C++ and 35 more in More... Sutter has 47 items.) Sutter's first 30 items are drawn from a series of issues published under the moniker, "Guru of the Week" (abbreviated "GotW") on comp.lang.c++.moderated, and this collection is now up to Item #66. The complete archive is at http://www.peerdirect .com/resources/. Most of the items in this book have the advantage that they were subjected to much public examination and discussion by many skilled C++ programmers when they were GotW entries. Sutter mentions a newsgroup contest to name this book. Knowing publishers as I do, however, there's no way this book was not going to be named E-something C++.
Essential C++ and Exceptional C++ are both in an official Addison-Wesley series called the C++ In-Depth Series edited by Bjarne Stroustrup, whose name is prominently displayed on the covers. I guess they needed a different series name because eventually they'll run out of words that start with E. Just joking. Knowing Bjarne, I am sure that only books of quality will include his participation and endorsement. I'd be inclined to recommend them even if I had not read them. I did read them, and I do recommend them.
DDJ