The work of Bjarne Stroustrup, one of the most important programming language designers of all time, has happened in parallel with that of one of the greatest filmmakers of all time, David Lynch, who passed away during the preparation of this edition. Regular readers of this magazine know that we are always eager to find analogies and synchronicities between our soulless computers and the arts, and if you think that this time it will be more of the same, follow your intuition.
The Elephant Man (1980)
C++ started its life as a language literally called “C with Classes”. To this day, this name still conveys a sad inheritance; for most people, that is all that C++ brings to the table. History proves that this is a short-sighted perspective.
Bjarne Stroustrup needed to build large and performant software projects, and thought that object-oriented programming was a fine paradigm to start with. He started working on a set of object-oriented extensions for the C programming language. Why C, you ask? Well, it was a little programming language that happened to be developed a few doors away from his office in Bell Labs, or so tells the legend:
Pascal was considered a toy language, so it seemed easier and safer to add type checking to C than to add the features considered necessary for systems programming to Pascal. (…)
At the time, I considered Modula−2, Ada, Smalltalk, Mesa, and Clu as alternatives to C and as sources for ideas for C++ so there was no shortage of inspiration. However, only C, Simula, Algol68, and in one case BCPL left noticeable traces in C++ as released in 1985.
Bundling OOP features on top of C was significant in various ways; object-oriented programming was not (yet) a mainstream thing in the early 1980s, mostly because implementations such as Smalltalk were unfortunately labeled as slow and clunky; hardware in the early eighties was not particularly powerful, and dynamic runtime binding of messages (a conditio sine qua non for one of the tenets of OOP, polymorphism) was considered inefficient.
What Stroustrup wanted was apparently what a lot of people wanted: a language that provided OOP features, such as those offered by Smalltalk, but compiled into binaries that would execute as fast as an executable written in C.
The solution Stroustrup adopted was not to adopt the Smalltalk model, but instead to take inspiration from fellow Scandinavians and to bolt ideas borrowed from Simula into C. The key innovation was to ensure compile-time binding of methods whenever possible, and in all the other cases, to use a vtable to dispatch messages as runtime, in the fastest possible way.
The resulting language, created by Stroustrup with the close collaboration of Andrew Koenig almost exactly 40 years ago at the time of this writing, was without any doubt, and against all odds, one of the most influential tools ever released in the history of programming.
However, just like Joseph Merrick, C++ was a freak, a curiosity; but one that enchanted programming elites with its capabilities and possibilities. And yes, sadly just like Merrick, C++ was often beaten by angry and uneducated mobs, who tried once and again to dismiss its towering status and to reduce it to a mere caricature.
Blue Velvet (1986)
Thanks to the extraordinary and sustained work of evangelization by Stroustrup himself, which included the release of the first edition of the eponymous book, C++ started making rounds on the press around this time.
Dr. Dobbs’ mentioned C++ for the first time in its October 1985 issue (to be exact, on page 96) in a review of a competing OOP system called Neon 1.0. But it was still too early; we had to wait until July 1987 for a review of that first edition of Stroustrup’s book, and to January 1989 for a full-blown comparison between C++ and Modula-2 (arguably, two major contenders for the OOP crown back in the day).
What about BYTE magazine? We find a first mention of C++ in an editorial in page 6 of the April 1986 edition, where the author talks about an upcoming OOP conference featuring names such as Brad Cox, Daniel Ingalls, Larry Tesler, and Bjarne Stroustrup. Quite the lineup, if you ask me.
A few months later, the August 1986 edition was entirely dedicated to the subject of OOP, with a review of Stroustrup’s book on page 63, and an article by Larry Tesler about the developer experience of using OOP languages, using C++ as one example.
But just like Lynch’s “Blue Velvet”, C++ still received a mixed response in those early days. Developers and their organizations were still too much entrenched in the structured ways of Pascal, the predominant language in both Macs and PCs, and did not yet see the symbolism behind OOP. We could all feel that something great was brewing there, but we needed to rewatch the film rewrite our apps quite a few times more, before we understood the symbolism, and stopped focusing on that severed ear on the floor.
Wild at Heart (1990)
According to Stroustrup himself, around 150'000 developers were writing C++ for a living in 1990.
In other words, the C++ user population doubled every 7.5 months or so.
Major and minor vendors, ranging from behemoths such as Intel, Microsoft, or Borland, to smaller ones like Watcom, Zortech, and Comeau, to free software communities like the GNU project, were all delivering more and more powerful compilers. Again according to Stroustrup,
Borland, the largest single C++ compiler supplier, publicly stated that it had shipped 500,000 compilers by October 1991.
The ecosystem around C++ was already strong enough for the Microsoft Systems Journal to start including a “C/C++ Q&A” section in the March/April 1992 issue (volume 7, number 2). Slightly earlier than that, Apple included articles about C++ in their “develop” journal, like for example in issue 2 of April 1990, where we find a style guide and a guide to use C++ with MPW handles under the standard Macintosh memory manager.
As Scott Meyers and Stroustrup repeatedly observed, C++ was already a federation of four languages into one, not just a single language: C, Object-Oriented C++, Template Metaprogramming, and The Standard Template Library.
The 1990s was the time of the discovery of the curiously recurring template pattern, among others by James Coplien. The time of Alex Stepanov giving us the Standard Template Library. The time of Metrowerks CodeWarrior on the Mac. The time of Marshall Cline’s C++ FAQ, nowadays merged with Stroustrup’s own. The time of every framework bundling its own, incompatible, home-made string
class. The time of growth of the C++ committee, which by the way has always been open to all and anyone, as explained by (you guessed it) Stroustrup:
The members of the [The American National Standards Institute committee for C++, or ANSI J16] committee are volunteers who have to pay (about $800 a year) for the privilege of doing all the work. Consequently, most members represent companies that are willing to pay fees and travel expenses, but there is always a small number of people who pay their own way.
During the 1990s, developers sang “Love Me Tender” to C++, and it became the object-oriented programming language by antonomasia. Books like the first and second edition of Grady Booch’s “Object-Oriented Analysis and Design with Applications”, and the Gang of Four’s “Design Patterns” book, all featured code samples in C++.
But this short honeymoon moment, just like Lula’s and Sailor’s, would be over soon.
Mulholland Drive (2002)
The almost simultaneous releases of Java and the World Wide Web sent shockwaves throughout the industry. Software developers stopped focusing on desktop operating systems, much to the dismay and urgency of Microsoft, who promptly drowned the market with a bug-ridden web browser for almost a decade.
As explained by Stroustrup,
In October 1991, the estimated number of C++ users was 400,000. The corresponding number in October 2004 was 3,270,000. Somewhere in the early ’90s C++ left its initial decade of exponential growth and settled into a decade of steady growth.
Java came bundled with the killer feature that stopped the meteoric ascension of C++: a garbage collector. Forget about those new
/ delete
cycles: just allocate objects and leave them there, somebody will take care of cleaning up the heap for you.
It is not like you could not use garbage collectors with C++; there have been a few proposals for such a thing. But the tight control of resources provided by manual memory management proved too much of a burden for some applications, and C++ never got a standard garbage collection system.
Under this pressure, the work on C++ became slower (at least, as seen from the outside), and seemingly more chaotic. After the release of the 1999 edition of the standard, work seemed to stop, while the world moved towards networking applications built on top of HTML and HTTP, applications that were better served by garbage-collected runtimes and technologies collectively referred to as LAMP.
The C/C++ community became obsessed, just like Betty Elms (or was it Diane Selwyn?), with Java the seductress, akin to Rita (or was it Camilla Rhodes?) As a result, the development of the language was apparently brought almost to a halt:
“Silencio, no hay banda”.
We just got a short update of the standard in 2003, and we would have to wait 8 more years for (finally!) a radical upgrade to the language.
This was a period during which developers starting exploring other options, like the functional paradigm, scripting languages such as JavaScript or Ruby, or jumping on the concurrency wagon (the “Free Lunch is Over”, remember?) with languages like Erlang, Go, or Scala.
The Story of a Small Bug (2020)
Thankfully, C++11 arrived, even if when it did, many developers had walked away in dismay.
Stroustrup starts the preface of the 2014 massive 4th edition of his magnus opus with the following observation:
C++ feels like a new language. That is, I can express my ideas more clearly, more simply, and more directly in C++11 than I could in C++98. Furthermore, the resulting programs are better checked by the compiler and run faster.
The list of changes between C++98 and C++11 is, indeed huge, including move semantics, lambdas, auto
and decltype
, the curly-bracket initialization syntax, defaulted functions, nullptr
, and so much more. Those who suffered (like the person writing these lines) the shenanigans of C++98 should definitely give a shot to C++ once again. According to Deitel & Deitel, the 4 big things of C++20 are: ranges, concepts, modules and coroutines. Can you recognize your C++ now?
Of course, my opinion, as usual, is not the same as the rest of the industry. 2022 ended up being “the year of the C++ successor languages”, according to the ACCU. And successors we got: Rust, Zig, Carbon, Circle, Hylo, Vale; how many more hype cycles of rewriting the world into yet another language do we need to go through? We are still stuck in the same tar pits. For the anecdote, let us see what happened to @mcc just a few weeks ago:
So I switch from C++ to Rust because debugging C++ packaging and linking errors is the most painful thing in the world and then my Rust crates wind up building C++ packages and then the C++ packages fail to build because debugging C++ packaging and linking errors is the most painful thing in the world
But wait, there is more: as mentioned by Fireship in a recent video, the Defense Advanced Research Projects Agency is proposing to use a program called TRACTOR to translate C and C++ code into Rust using AI and LLMs. Excellent idea. Let us trust our defense to an LLM. What could possibly go wrong?
Stroustrup designed C++ to help us build huge projects. How huge are they? Taking a look at some estimations gathered from various sources online, and even if “lines of code” is not always a suitable metric, we can be genuinely impressed.
Project | Estimated Lines of Code |
---|---|
Microsoft Windows | ~50 million |
Chromium | ~45 million |
Mozilla Firefox | ~21 million |
LibreOffice | ~12 million |
MySQL | ~9 million |
Blender | ~6 million |
Qt Framework | ~5 million |
Unreal Engine | ~3 million |
Yes, I think the task is fulfilled, Bjarne.
What many programmers do not realize is the following: modern C++ can be as safe as Rust. It can; it just requires humans to think, something that, in the age of the LLM, is becoming the greatest challenge of our time. If you do not believe me, ask Herb Sutter for details.
The C++ galaxy is more vibrant than ever, with a new release of the programming language every 3 years (2011, 2014, 2017, 2020, 2023, and 2026 upcoming), solid support from an incredibly large array of vendors, extraordinary open-source compilers, a never-ending list of available tools… yet, we insist in sticking with old perceptions and misconceptions. Insert sad emoji face here.
Let us quickly review the state of the ecosystem. Need a package manager? vcpkg by Microsoft and Conan seem to lead the pack, but we also have Spack for supercomputers, build2 inspired by Rust’s cargo
, with packages at cppget, Buckaroo, Cabin, Hunter, xrepo, and cpm… made by and for CMake.
Speaking about CMake, what about build tools? Well, we have the veteran GNU Autotools, Meson, Bazel, SCons, tipi.build, Soup, Pixi, Mamba, Conda, and BitBake.
And what other tools and libraries should we mention? cdecl. Valgrind. Boost. Doxygen. Catch2. POCO. A myriad of awesome header-only libraries. Desktop GUI toolkits like Qt, wxWidgets, and JUCE. Web frameworks like Cutelyst (made with Qt), Drogon, libhttpserver, Lithium, or userver. A lot of awesome stuff.
And… yes. Lots and lots of string implementations, sadly. I agree with you, Bubba, initialization options abound. There are also plenty of cast operators: dynamic_cast
, static_cast
, reinterpret_cast
, and const_cast
, by the way. Bonus points if you know the differences among them. Le sigh. The most interesting things in life demand some effort, clearly.
Let us not drown from the incompetent perspective of those influencers disliking C++ on Reddit. We do not need yet another programming language claiming to be the next C++; we can learn to use the one we have right now, applying the best practices we can find.
Maybe it is time to revisit C++ with renewed eyes and also, by the way, to find out who killed Laura Palmer. Because, seriously.
Cover photo by Jeremy Yap on Unsplash.