This page concentrates on personal opinions and general questions related to philosophy. For questions that more directly relate to C++ language features and the use of C++, see my C++ style and technique FAQ. For links to useful sources of C++ information, see my C++page. For information about my books (incl. reviews and support information), see my book list. For papers and ISBNs for translations of my books, see my publication list.
For people who can't receive sound, here is a suggestion: Both of my names are pronounced with two syllables: Bjar-ne Strou-strup. Neither the B nor the J in my first name are stressed and the NE is rather weak so maybe Be-ar-neh or By-ar-ne would give an idea. The first U in my second name really should have been a V making the first syllable end far down the throat: Strov-strup. The second U is a bit like the OO in OOP, but still short; maybe Strov-stroop will give an idea.
Yes, this probably is the most frequently asked question :-)
Here are links to
What what looks "cool and modern" someone is often considered bad taste by someone else. Also, fashions change fast.
Very plain html downloads and displays faster than anything else, and many people suffer from slow connections to the web.
See a note about the structure, contents, and aims of "The C++ Programming Language (3rd edition)": The book is aimed at programmers with some experience and a wish to master C++. It is not aimed at non-programmers trying to learn their first programming language or casual programmers trying to gain a superficial understanding of C++ as fast as possible. Consequently, this book focuses on concepts and techniques and goes to some pain to be complete and precise.
If you want to know why C++ is the way it is, have a look at The Design and Evolution of C++ (D&E). Understanding the design criteria and constraints helps writing better programs.
Have a look at the ACCU (The Association of C and C++ Users) site. This is one of the best sites for book recommendations by experienced programmers who are not afraid to speak their mind (booksellers tend to give rosy reviews, and reviews of the form "This book is perfect, I love it, I have read almost three chapters, and can't wait to read more" are worse than useless - why anyone would take advice on how to learn C++ from someone who completely lacks C++ experience beats me). The ACCU rates books for level of experience required and overall quality.
On the other hand, if you want to be fully comfortable with all the major C++ language constructs, with data abstraction, Object-Oriented programming, generic programming, Object-Oriented design, etc., you can easily spend a year or two - if you aren't already acquainted with those techniques.
Is that then the time it takes to learn C++? Maybe, but then again, that is the timescale we have to consider to become better designers and programmers. If a dramatic change of the way we work and think about building systems isn't our aim, then why bother to learn a new language? Compared to the time required to learn to play the piano well or to become fluent in a foreign (natural) language, learning a new and different programming language and programming style is easy.
For more observations about learning C++ see D&E or a note from comp.lang.c++ that I wrote some time ago.
See Learning Standard C++ as a New Language for a discussion of the choice of C++ constructs, techniques, and libraries for early learning.
You'll need a textbook for learning C++. This is the case even when your implementation comes with ample on-line documentation. The reason is that language and library documentation together with sample code are not good teachers of concepts. Typically such sources are silent about why things are the way they are and what benefits you can expect (and which you shouldn't expect) from a technique. Focus on concepts and techniques rather than language-technical details.
When choosing a book, look for one that presents Standard C++ and use the standard library facilities in an integrated manner from the start. For example, reading a string from input should look something like
string s; // Standard C++ style cin >> s;and not like this
char s[MAX]; /* Standard C style */ scanf("%s",s);Look for book recommendations from programmers with solid C++ experience. Remember that no one book is the best for everyone. Have a look at the book reviews on the ACCU (The Association of C and C++ Users) site.
Aim to write idiomatic C++: avoid simply writing code in the style of your previous language using C++ syntax; there is little to be gained from simply changing syntax. See Learning Standard C++ as a New Language a discussion of how one might approach C++.
For Macs, see Apple.
Caveat: If you want to use "free" compilers for commercial work, be sure to read all legal rules and restrictions attached.
There are a variety of old C++ implementations floating around on the web and on CDs. I do not recommend an old C++ compiler for learning C++ or for new production use. There is little to be gained by fighting your way through bugs that have been fixed years ago or limitations that have been lifted years ago by the standard committee.
For good quality free (parts of) the standard library, see SGI's STL site and STLport.
This is the language and standard library described in The C++ Programming Language (3rd edition). The C++ compiler and library suppliers are already shipping implementations that are quite close to the draft standard.
The C++ standard (ISO/IEC 14882) is available for downloading at the National Committee for Information Technology Standards Electronic Store. The cost is (as I write this) US$18.00 payable on-line via credit card. The downloaded document is in PDF form, 2794KB total size.
The draft standard as it were in later stages of the standards process can be downloaded for free.
Be warned that the standard is not a tutorial; even expert programmers will do better learning about C++ and new C++ features from a textbook.
Most of the features I dislike from a language-design perspective are part of the C subset of C++ and couldn't be removed without doing harm to programmers working under real-world conditions. C++'s C compatibility was a key language design decision rather than a marketing gimmick. Compatibility has been difficult to achieve and maintain, but real benefits to real programmers resulted, and still result today. By now, C++ has features that allows a programmer to refrain from using the most troublesome C features. For example, standard library containers such as vector, list, map, and string can be used to avoid most tricky low-level pointer manipulation.
My personal view is that the key principles should be
I briefly presented some of my ideas at a panel at SD2001w. Please note that this reflects my personal view of where C++ ought to go rather than committee policy.
Andrew Koenig and I are working on a replacement based on the actual text of the ISO standard. This work was delayed because of difficulty in getting permission from ISO to use the actual standards text. (I considered using any other text disloyal to my friends and colleagues on the standards committees and a disfavor to the C++ community). Our work on this "ARM++" has been delayed (again), so I don't dare give an estimate of when it will become available.
For 2000 printings - including the hardcover "special edition" - I have two new appendices on Locales and Standard-Library Exception Safety.
The German translation of the "Special Edition" is referred to as the 4th edition.
Seriously, the difference between the current printings of the special edition and the 3rd edition is just the hard cover (and the price difference implied by that stronger cover).
If I were a C++ programmer who hadn't read The C++ Programming Language (3rd Edition), I'd buy and read either the 3rd edition or the special edition. If I used my textbooks and references heavily, I'd choose the hard cover. The cover on the 3rd is the best soft cover available, but it doesn't equal the special edition's hard cover.
If I already had the 3rd edition, I'd buy the SE if my current copy were fraying or if my copy were an early printing.
Compared to the first printing, the special edition and the most recent printings of the 3rd edition have about 1,000 corrections and clarifications. As a heavy C++ user, I find that significant. There are also the two new appendices (just over 100 pages; available for download: Locales and Standard-Library Exception Safety).
Existing material has not moved around so page numbers can be used to refer to material in old printings, new printings of the 3rd edition, and in the SE.
The SE also has an improved index.
Also, where possible, prefer the standard library to non-standard "foundation libraries" and try to minimize use of proprietary extensions.
Much of the relative simplicity of Java is - like for most new languages - partly an illusion and partly a function of its incompleteness. As time passes, Java will grow significantly in size and complexity. It will double or triple in size and grow implementation-dependent extensions or libraries. That is the way every commercially successful language has developed. Just look at any language you consider successful on a large scale. I know of no exceptions, and there are good reasons for this phenomenon.
(The paragraph above was written before Java1.1. I confidently predict that Java will acquire a template-like mechanism and improved support for concrete types. It simply has to do that to be reasonably complete. In addition, it will also undergo many minor changes - mostly extensions. Later still (fall 1998), I found a proposal from James Gosling for adding concrete types, operator overloading, and support for numeric computation to Java: The Evolution of Numerical Computing in Java and a debunking of some Java myths by W. Kahan, UC Berkeley, One of the world's leading numerical analysts: How Java's Floating-Point Hurts Everyone Everywhere).
I find most of the Java advertising on TV and in print inaccurate and offensive. Denouncing all code written in languages other than Java as "contamination" is insulting to programmers. Suggesting that all "legacy code" should be rewritten in Java is wildly unrealistic and irresponsible. Sunsoft and its followers seem to consider this kind of bombast necessary to fight "the evil empire of Microsoft" but insults and hype simply drives programmers who prefer to use a variety of programming languages into the arms of Microsoft.
Java isn't platform independent; it is a platform. Like Windows, it is a proprietary commercial platform. That is, you can write programs for Windows/Intel or Java/JVM, and in each case you are writing code for a platform owned by a single corporation and tweaked for the commercial benefit of that corporation. It has been pointed out that you can write programs in any language for the JVM and associated operating systems facilities. However, the JVM, etc., are heavily biased in favor of Java. It is nowhere near being a general reasonably language-neutral VM/OS.
Personally, I'll stick to reasonably portable C++ for most of the kind of work I think most about and use a variety of languages for the rest.
Clearly, I'm no great fan of proprietary languages, and quite a fan of open, formal standards.
"Several reviewers asked me to compare C++ to other languages. This I have decided against doing. Thereby, I have reaffirmed a long-standing and strongly held view: Language comparisons are rarely meaningful and even less often fair. A good comparison of major programming languages requires more effort than most people are willing to spend, experience in a wide range of application areas, a rigid maintenance of a detached and impartial point of view, and a sense of fairness. I do not have the time, and as the designer of C++, my impartiality would never be fully credible.
I also worry about a phenomenon I have repeatedly observed in honest attempts at language comparisons. The authors try hard to be impartial, but are hopelessly biased by focusing on a single application, a single style of programming, or a single culture among programmers. Worse, when one language is significantly better known than others, a subtle shift in perspective occurs: Flaws in the well-known language are deemed minor and simple workarounds are presented, whereas similar flaws in other languages are deemed fundamental. Often, the workarounds commonly used in the less-well-known languages are simply unknown to the people doing the comparison or deemed unsatisfactory because they would be unworkable in the more familiar language.
Similarly, information about the well-known language tends to be completely up-to-date, whereas for the less-known language, the authors rely on several-year-old information. For languages that are worth comparing, a comparison of language X as defined three years ago vs. language Y as it appears in the latest experimental implementation is neither fair nor informative. Thus, I restrict my comments about languages other than C++ to generalities and to very specific comments."
That said, I consider C++ the best choice in programming language for a wide variety of people and applications.
When looking at a language comparison consider who wrote it, consider carefully if the descriptions are factual and fair, and also if the comparison criteria are themselves fair for all languages considered. This is not easy.
Well written C tends to be legal C++ also. For example, every example in Kernighan & Ritchie: "The C Programming Language (2nd Edition)" is also a C++ program.
Examples of C/C++ compatibility problems:
int main() { double sq2 = sqrt(2); /* Not C++: call undeclared function */ int s = sizeof('a'); /* silent difference: 1 in C++ sizeof(int) in C */ }Calling an undeclared function is poor style in C and illegal in C++. So is passing arguments to a function using a declaration that doesn't list argument types:
void f(); /* argument types not mentioned */ void g() { f(2); /* poor style C. Not C++ */ }In C, a void* can be implicitly converted to any pointer type, and free-store allocation is typically done using malloc() which has no way of checking if "enough" memory is requested:
void* malloc(size_t); void f(int n) { int* p = malloc(n*sizeof(char)); /* not C++. In C++, allocate using `new' */ char c; void* pv = &c; int* pi = pv; /* implicit conversion of void* to int*. Not in C++ */ }Note the potential alignment error caused by the implicit conversion of the void* to a int*.
When converting from C to C++, beware that C++ has more keywords than C:
int class = 2; /* ok in C. Syntax error in C++ */ int virtual = 3; /* ok in C. Syntax error in C++ */Except for a few examples such as the ones shown above (and listed in detail in the C++ standard and in Appendix B of The C++ Programming Language (3rd Edition)), C++ is a superset of C. (Appendix B is available for downloading).
C++ is a direct descendant of C that retains almost all of C as a subset. C++ provides stronger type checking than C and directly supports a wider range of programming styles than C. C++ is "a better C" in the sense that it supports the styles of programming done using C with better type checking and more notational support (without loss of efficiency). In the same sense, ANSI C is a better C than K&R C. In addition, C++ supports data abstraction, object-oriented programming, and generic programming (see The C++ Programming Language (3rd Edition)"; Appendix B discussing compatibility issues is available for downloading).
I have never seen a program that could be expressed better in C than in C++ (and I don't think such a program could exist - every construct in C has an obvious C++ equivalent). However, there still exist a few environments where the support for C++ is so weak that there is an advantage to using C instead.
For a discussion of the design of C++ including a discussion of its relationship with C see The Design and Evolution of C++.
The current definition of C++ is The ISO C++ Standard described in The C++ Programming Language (3rd Edition).
You can find a more complete timeline and more detailed explanations in The Design and Evolution of C++.
The specific tasks that caused me to start designing and implementing C++ (initially called "C with Classes") had to do with the design of a distributed operating system.
You can find more detailed explanations in The Design and Evolution of C++.
At the time where I developed C++ - and before that when Ken Thompson and Dennis Ritchie developed Unix and C - AT&T was probably the worlds largest civilian user of (and consumer of) software tools. Then, we probably used a wider range of systems - from the tiniest embedded processors to the largest supercomputers and data-processing systems. That put a premium on systems that were applicable in many technical cultures and on many platforms. C and C++ were designed with such demands in mind.
Thus generality is essential, and proprietary features are seen as limiting the choice of platforms and vendors. As a consequence AT&T was and is a major supporter of formal standards (for example, ISO C and ISO C++).
Actually, AT&T made enough money on Cfront, my original C++ compiler, to pay for the development of C++ several times over.
Compiler vendors do not pay royalties to me or to AT&T for C++, and ISO standards are specifications intended for royalty-free use by everyone (once they have paid the ISO or a national standard committee for their copy of the standard).
Also, C++ supports programming techniques that allows memory management to be safe and implicit without a garbage collector.
Since 1987 or so, the focus of development the C++ language and its associated programming styles have been the use of templates, static polymorphism, generic programming, and multiparadigm programming. This is way beyond the scope of the much-hyped proprietary languages. Another key difference is that C++ supports user-defined types to the same extent as built-in types. This - especially in combination with the use of templates, constructors, and destructors - enables the C++ programmer to use programming and design techniques that (IMO) are more advanced than what is supported in the languages with which C++ is most often compared.
Standard C++ and the design and programming styles it supports owe a debt to the functional languages, especially to ML. Early variants of ML's type deduction mechanisms were (together with much else) part of the inspiration of templates. Some of the more effective functional programming techniques were part of the inspiration of the STL and the use of function objects in C++. On the other hand, the functional community missed the boat with object-oriented programming, and few of the languages and tools from that community benefitted from the maturing experience of large-scale industrial use.
Clearly, I don't think that garbage collection is the sole defining characteristic of "advanced" in the context of programming languages. In particular, note that C++ provides support for effective and efficient memory management techniques that can eliminate resource leaks without the use of a garbage collector. If you disagree, you can just start using a garbage collector for C++; there are good ones available.
void draw_all(vector< Shape*>& vs) // draw each element of a standard vector { for_each(vs.begin(),vs.end(),mem_fun(&Shape::draw)); }Here, Shape* will be an abstract base class defining the interface to a hierarchy of geometric shapes. This example easily generalizes to any standard library container:
template< class C> void draw_all(C& cs) // draw each element of a standard container { for_each(cs.begin(),cs.end(),mem_fun(&Shape::draw)); }
Jim Coplien's book "Multiparadigm Design for C++" (Addison Wesley, 1998) explores the use of multiple paradigms in the context of design and design methods.
I do not think that a defined subset or dialect of C++ is necessary for embedded systems programming (see my keynote at the Spring'99 Embedded Systems Conference). The embedded systems programming community would be better served by a group considering and documenting how the needs of the embedded systems community relates to C++. Different projects and organizations would then have a rational basis for their decisions of what part of C++ to use. The embedded systems community is diverse. Many currently rely on templates, some are using exceptions, and namespaces have no implications on the size or speed of programs. Only the language and library defined by the ISO C++ standard is flexible, general, and well-defined enough to serve the embedded systems community for the decades to come. In the relatively few cases where run-time space or efficiency is a problem with Standard C++ (usually because of sub-optimal implementations) a few compiler switches can help the optimizer (e.g. for some projects and for some compilers disabling exceptions may yield significant performance benefits - and sometimes it will not).
That said, writing C-style programs in C++ is for most applications not an optimal use of C++. To be a really effective C++ programmer, you must use the abstraction mechanisms and the type system in a way that fits reasonably with their intent. Trying to ignore or defeat the C++ type system is a most frustrating experience.
Writing Smalltalk-style in C++ can be equally frustrating and sub-optimal as writing C-style code in C++.
Of course not. Read the real IEEE interview.
There have been at least a dozen languages called D. See D&E for more name trivia.
C++ was initially designed and implemented as a set of general facilities addressing some specific problems that I and my colleagues faced. The generality - and efficiency - of the facilities provided turned out to serve much wider needs than I had anticipated. The emphasis on general facilities - as opposed to the provision of specific solutions to specific problems - has remained with C++ and has served its community well as the specific problems facing the community have changed over the years.
Seriously, I'm looking for fundamental ways of improving the tools and techniques we use to build large real-world systems.