Despite its stature and storied history in programming circles, C++ has only been around since 1991. Even though other programming languages like Java and C# have been introduced during its lifetime, C++ remains one of the most commonly used languages in application development.
One of the reasons C++ has remained so popular is the fact that it is an evolving programming language. The more C++ is used in application development the more tools, features and techniques are developed to supplement its already considerable power. In his book, Effective C++: 55 Specific Ways to Improve Your Programs and Designs, 3rd Edition, Scott Meyers discusses some of the best practices programmers have established for C++. An excerpt of that book is available in a free download from TechRepublic.
In the following interview, Scott Meyers talks about some of the most significant changes he has seen take place in the C++ universe and how those changes have given an edge to application developers.
Title: Effective C++: 55 Specific Ways to Improve Your Programs and Designs, 3rd Edition
Author: Scott Meyers
Publisher: Addison Wesley Professional
ISBN: 0321334876. Copyright 2005
[TechRepublic] In your book you discuss the many changes that have occurred in the C++ universe since 1991. When it comes to C++ as a language, what do you see as the most significant change in the past decade?
[Scott Meyers] There is no doubt that the most significant change has been what we might call "the rise of templates." Templates were originally envisioned as a way to support "containers of T," but we now recognize that they are vastly more powerful than that. The STL, the notion of generic programming, policy-based design, templatemetaprogramming, and expression templates are all technologies that have proved their practical worth and that require template capabilities beyond containers of T.
All modern C++ libraries take advantage of the power of templates, and in fact the notion of "modern" C++ programming is virtually synonymous with programming that makes liberal use of templates. That's why the new edition of Effective C++ not only contains a chapter devoted to templates; it also mentions them throughout the book. You can't be an effective C++ programmer these days without having a good understanding of how to use templates.
[TechRepublic] For programmers migrating from languages such as Java and C#, you suggest C++ can be a bit of a challenge initially. What do you think is the biggest hurdle for those programmers to overcome?
[Scott Meyers] One of the most challenging aspects of moving from one language to another is overcoming false assumptions. It's hard to be on the lookout for trouble if you don't realize that it's possible. For example, C++ objects can sometimes go uninitialized, but, as far as I know, that's impossible in Java or C#.
C++ has a number of things that lead to undefined behavior, again, something that can't exist in Java or C#. C++ objects can have multiple addresses, which isn't possible in Java or C#. In the third edition of Effective C++, I mention these things and several others, because it's important for developers from other languages to understand when the fundamental behavior of the language is other than what they are likely to expect.
Perhaps that's the biggest hurdle for such developers: becoming aware of subtle, but fundamental, differences in behavior in C++ compared to the language they've been using.
[TechRepublic] In your book you list 55 specific ways to improve C++ program design. Are there any specific improvements that stand out in your mind as the most effective or of most benefit?
[Scott Meyers] I take satisfaction in knowing that much of the design advice I made in earlier editions continues to apply, e.g., the proper use of public inheritance; the proper use of pure virtual, impure virtual, and nonvirtual functions; the aggressive use of const, etc. But the third edition contains new advice that I think is critical, too.
Three ideas that particularly stand out in my mind are the importance of using objects to manage resources, the importance of writing exception-safe code, and the many design alternatives—including their advantages and disadvantages—to virtual functions. Effective C++ has always had lots of nuts-and-bolts advice about using C++ well, but I've also always put in lots of design advice, often in the form of motivations or rationales for the specific C++ programming guidelines. I think the third edition upholds this tradition of building good programming practices on a foundation of solid design.
Mark W. Kaelin has been writing and editing stories about the IT industry, gadgets, finance, accounting, and tech-life for more than 25 years. Most recently, he has been a regular contributor to BreakingModern.com, aNewDomain.net, and TechRepublic.