Today I came across the video of a talk of Bjarne Stroustrup, where, among other things, he states that C++ is not an object oriented language. This contradicts what many authors write about C++, and what many people believe to know about C++. After all, C++ has classes and objects and inheritance and what no. So, it has to be an object oriented language, right? It’s not that simple.
What does “object oriented language” mean?
It depends largely on the definition of an object oriented language. If you define an object oriented language as a language that provides the possibility to do object oriented programming, then C++ is an object oriented language.
But, then, depending on what features you define to be essential for object oriented programming, C is an object oriented language as well. I have seen C-code that had something resembling constructors, methods, virtual function tables and so on.
However, if you define an object oriented language as a language that enforces object oriented programming, where you put everything in a class, and that provides lots of features that make object oriented programming an easy task, then C++ is not an object oriented language.
Comparing C++ with object oriented languages
With that in mind, we may be able to understand some people who come from Java or C# and consider C++ a bad language: They expect an object oriented language with all its cozy features like e.g. a garbage collector and are disappointed because they don’t get what the brochure promised.
It even might not matter to them that C++ has to offer more than just the possibility of object oriented programming – which is one of its strengths – because they don’t know or don’t care about those other features.
So, for people who want to build an application in a purely object oriented way, one should not advertise C++ as the language to use, because it might not be. C++ is not a purely object oriented language, and if you are in need of such a language, it is not a bad language, it is simply the wrong language.
If not object oriented, what is it?
So where does that leave C++? It’s not a object oriented language, although you can do object oriented programming with it. It is not a procedural language, although C is a subset. It’s not low level, because it provides higher level abstractions, but you can twiddle bits and fool around in memory directly, if you have to.
C++ provides features for generic programming, includes a Turing complete compile time (meta-)programming language and you can even do functional programming and actor based programming if you are crazy enough.
For all this, C++ is called a multi paradigm language. You can do almost everything with it, if you have or want to, but it is not the best language for everything. C++ is a tool among many, and it is the programmer’s task to choose the right tool to solve his problem. It is also his duty to know how to wield the tool, i.e. do know when to use the object oriented or procedural or generic facets of C++.
This multiplicity may make C++ harder to learn than other languages, but it can also make it so much more fun to have all the possibilities at your fingertips, once you know when and how to use and combine them.