The Mastermind of C++, or… Part 6 C++ and OO

Ianjoyner
5 min readJul 23, 2024

--

This is the sixth of a series of articles examining a 2009 interview with Bjarne Stroustrup. The first part is here with links to the other parts:

Part 1

Part 5

C++ gives OO a Bad Name

Asked: “Kernels like Linux’s or BSD’s are still written in C. Why haven’t they moved to C++? Is it something in the OO paradigm?”

Stroustrup: “…You seem to equate C++ use with OO. C++ is not and was never meant to be just an object-oriented programming language.”

This is the problem with C++, not with OO. The intention with classes and objects is that everything is structured around classes, not just something to occasionally use. OO profoundly changes the way programs are organised. C++ means programmers still predominantly structure things around a global environment (tamed a little by namespaces).

I have written about how C++ is the antithesis of OO, doing more damage to OO than any non-OO language. C++ is the mix of opposing paradigms. C++ is an old top-down command-and-control language. That is opposite to OO. That is why the old C people including Linux Torvalds hate C++. They are right, you should only program one way or the other.

https://medium.com/@ianjoyner/e1ea529bcf60

I wrote about the origins of the class here:

https://medium.com/@ianjoyner/the-foundations-at-the-core-of-c-are-wrong-part-6-c566cf4b179d

This also explains why the C way of structuring as perpetuated in C++ around globals is wrong.

While the full implications of OO were not evident in Simula’s classes and inheritance, Stroustrup never understood that when he thought a cheap-and-nasty macro version of classes and inheritance would suffice in ‘C with Classes’. The changes made then and since have never sufficed to make C++ an OO language. But neither should we accept Stroustrup’s excuse that C++ was never intended as an OO language. C++ fails to get the full benefit of OO.

Stroustrup makes the point that C++ is more about generic programming. Well genericity in the form of C++’s cheap-and-nasty template macro equivalent did not appear in C++ until more than a decade after C++ was first worked on. If is is the case the C++ is more about generics why did it take more than 10 years to add templates to C++?

Stroustrup: “Generic programming in the typical C++ style relying heavily on templates is widely used where you need both abstraction and performance.”

Statically typed object-orientation with classes needs generics to tighten up the type system so you can’t assign LIST [WABE] (list of WABE objects) to LIST [MIMSY] where class WABE is incompatible with class MIMSY. C++ did not have this at the beginning. In statically-typed languages classes and generics go together. Dynamically-typed OO languages such as Smalltalk do not need generics at all, but you won’t catch many common errors at compile time. Again this results in a different style of programming. However, Alan Kay says: “I made up the term “object-oriented,” and I can tell you I did not have C++ in mind.” And “This is the most pernicious thing about C++ and Java in that they think they’re helping the programmer by looking as much like the old thing as possible but in fact they’re hurting the programmer terribly by making it difficult for the programmer to understand what is really powerful about this new metaphor.

Stroustrup: “I have never seen a program that could be written better in C than in C++. I don’t think such a program could exist.”

That is a very biased statement. Many C programmers would disagree. However, C is clearly not meant to be structured in an OO way. You can do C in an OO style with function pointers, but it is a lot of work and even further away from OO than C++. There is little point. Even C++ will improve on that for you.

However, both C and C++ are now old and compromised languages, compromised by the constraints of limited 1960s computing in both terms of hardware and compiler technology. We can do far better than C for systems programming, and even further for general-purpose application programming which should not have to deal with the details that C and C++ force you to deal with.

Stroustrup: “There is nothing that requires you to go hog-wild with exceptions, class hierarchies, or templates.”

Sure, they should be used naturally, but C++ allows programmers to completely ignore OO facilities, using C++ as a dubiously better C.

Stroustrup: “A good programmer uses the more advanced features where they help more directly to express ideas and do so without avoidable overheads.”

Most programmers are just struggling to get programs work correctly and are not overly concerned with overheads. That is right, leave it to the compiler, runtime, and operating system to choose whatever uses the least overhead. This is a burden C++ pushes to the programmer.

Further down talking about generic programming with templates, Stroustrup makes this claim: “Java’s and C#’s recent addition of “generics” are attempts to follow C++’s lead, and are often — incorrectly, I think — claimed to improve upon templates.”

Let’s just dispel this “C++ lead”. C++ did not have templates until the late 1990s. Eiffel and other languages had generics from the mid-1980s. C++’s templates are just a cheap-and-nasty macro facility. C++ and Stroustrup did not invent this stuff, just hacked it in rather badly into the base of C, where these things really don’t belong. I find this pretence, like C to have invented these styles of programming not just disingenuous, but dishonest. I do agree that Java generics were added later and left a lot to be desired.

A section on OOP and Concurrency follows. Stroustrup is correct to identify that concurrency was at the beginning of OO in Simula. Simula had support for logical concurrency in threads and processes. I say logical because these are structured around what we want them to do, rather than just containers for a process that does anything and we don’t care what.

In the 2009 publication, it is still unclear what support C++ would have for concurrency and what form it would take. Perhaps C++ will steal the Eiffel idea of concurrency based around waiting for conditions (event-style programming), which again is a very high-level, logical, yet minimal extension. However, C and C++ are not good vehicles for general concurrency. Yes C has fork, but this is an operating system level process.

https://queue.acm.org/detail.cfm?id=3212479

Part 7

--

--