CeePlusPlus has long been the brunt of criticism, much of it deserved. That said, billions of lines of productive code have been written in it (and this continues to this day). This page is not intended as a general critique or defense of CeePlusPlus, but instead examines one oft-heard claim from some C++ detractors - that C++ is not object-oriented. AlanKay, the inventor of SmalltalkLanguage, is famous for saying "I invented the term ObjectOriented, and C++ isn't what I had in mind". Unfortunately, he doesn't supply us with a definition of what he does have in mind.
One common definition of OO (admittedly found in many C++ texts) is that it involves "PolymorphismEncapsulationInheritance". Two apparent flaws in that definition betray its C++ bias; "inheritance" is used when the more generic notion of subtyping will suffice; and what is meant by polymorphism is really subsumption - the ability to use a subtype in a context where a supertype is expected. There are many other types of polymorphism (see CategoryPolymorphism) which are considered outside the scope of OO (though one of them, ParametricPolymorphism, is implemented in C++ via templates).
Even with this refactoring, which gives us "subtyping, subsumption, and encapsulation" (with the remaining caveat that the first two are mostly applicable in statically-typed languages, though dynamic typing allows us to do the same stuff - and more), C++ fits all three bills.
Arguments against CeePlusPlus being OO seem to fall in the following categories:
GarbageCollection is an implementation feature, not a language feature - and regardless, it can be implemented using C++. Saying C++ needs GarbageCollection to be OO is akin to saying that C needs stdio to be procedural. Anyone arguing that a language must abstract away all low-level features to be OO is trying to push their own proprietary definition of OO and should be ignored. OO isn't about achieving maximum abstractness, it's about being a better model than procedural for all the various problem domains we encounter.
Garbage collection is, in most cases, a language feature. Smalltalk, Java, etc. implementations are required to have it; neither of those languages have any means to manually reclaim an object that is no longer used. Likewise, there are many reasons that GarbageCollection in C++ is difficult (destructor semantics, inability to tell the difference (at runtime) between a pointer and an int, etc. It's been done; but it's easy for unfriendly C++ programs, or overly-aggressive optimizing compilers, to break.
So the gist is that CeePlusPlus isn't OO because for GarbageCollection to work properly, everything must be an object? Or memory operations must be codified in such a way for GarbageCollection to work?
No; the argument is that OO programs should represent a higher level of abstraction; and manual memory management breaks that abstraction.
Good point - however most claim Java is OO, yet it's GarbageCollection breaks sometimes. Of course I prefer using a MemoryTracker? to GarbageCollection - I can code a test to see if any pointers weren't deallocated properly.
Guess what? Your MemoryTracker? most likely has a tracing GarbageCollector under the hood - but one which doesn't free the garbage it discovers; instead it reports it as a MemoryLeak. See RationalPurify for more on how this works.
Personally I think GarbageCollection is often an anti-pattern that encourages overly-loose memory practices.
GarbageCollection isn't always a panacea, and it still has performance issues for many applications. Furthermore, GarbageCollection can't collect all garbage; only those objects not reachable from the RootSet?. It is easy to write programs that will run out of memory quickly even with a garbage collector - simply leave a bunch of pointers lying around to objects you no longer intend to use.
That said, the presence of a GarbageCollector does eliminate several classes of bugs. Many types of memory leaks (including the unrecoverable kind where an object isn't freed but no references to it exist), and all of the nastier bugs associated with freeing objects twice.
I guess it's a matter of technique. My memory tracker does a few things:
I'm 63/64 white, and 1/64 native American (roughly) - does that mean I'm not white?
Nowadays, no. Of course, at one point in the history of the UnitedStates, having any African biological heritage made essentially made you "black", even if it the majority of your blood was of European origin. (Nowadays, this particular standard no longer applies, at least not legally).
Who claims that everything must be an object to be OO? That sounds like an arbitrary decision that wasn't based on real-world feedback. Preventing choice isn't power, it's a flaw - real power means being able to break rules when deemed necessary. I don't think OO means ObjectObsessive?.
I think the best argument that CeePlusPlus isn't object oriented is that "CeePlusPlus lets the developer choose what level of OO to use". Remember, the procedural vs. object wars are not over.
I know we're all programmers here, but some of us who share AlanKay's opinion that CeePlusPlus is not what he had in mind are talking about the overall experience, not a checklist of features and benefits. Some things - even important things - are soft rather than hard. I would be very hard pressed to describe the difference between an intimate experience dominated by lust and one dominated by love. It would be very wrong to conclude, therefore, that no such difference exists.
For me, the closest I can come to answering the question IsCeePlusPlusObjectOriented inevitably involves a comparison with the SmalltalkLanguage, because for me Smalltalk is the canonical object-oriented environment. I therefore think it might be more helpful think in terms of soft, rather than hard, aspects. I view the question as more like a comparison between CeePlusPlus and Smalltalk along dimensions like:
Well, AlanKay might have invented the term, but the paradigm was invented by Nygaard and Dahl. Now if we look for ObjectOrientedProgramming as defined by Nygaard in his seminal "Beta book", there's nothing like the laundry list above.
So let's rephrase things a bit:
Everybody should be happy now.
I'm happy because I just realized a lot of people "own" the definition of OOP, so disagreement over "proper OO" is inevitable. It doesn't matter who drew it up, named it, implemented it best, adapted it best, or discovered the most advanced patterns.
Nobody owns the definition. Since KristenNygaard and OleJohanDahl are widely recognized as the inventors, most people would recognize NygaardClassification as authoritative.
If somebody else comes with an obviously different definition one the following cases may apply:
If both C++ and Smalltalk are ObjectOriented, then Smalltalk needs a new classification:
That's what a C++ programmer would say, because his idea of ObjectOriented is different than a Smalltalkers.
If ObjectOriented is to have any useful meaning, it should be a consistent one.
In C++ you create a class with a file containing strings in a special format, in Smalltalk you send a message to the Class object to create a new class. Smalltalk is a live system of objects, C++ is a bunch of strings until compiled and executed, it's not a runtime system.
Something which is simultaneously a strength and a weakness - for both languages
If anyone could ever agree on a single definition of ObjectOriented there wouldn't be so much disagreement, but I imagine when a Smalltalker see's a C++ environment, he feels like it's missing too many things Smalltalk has, to be considered fully OO. Whether correct or not, it's certainly an understandable position.
But that's the problem. None of the definitions of OO, even that promulgated by AlanKay himself, says anything about what you are discussing. None of the DefinitionsForOo I've read (at least those worthy of being taken seriously) claim anywhere that an integrated environment, an ImageBasedLanguage, or the ability to tweak the runtime system, etc., are requirements for OO-ness). I'll agree that Smalltalk has lots of things C++ lacks, the latter being a highly static language with runtime intentionally decoupled from development environment. No argument there. But what does that have to do with OO? Not a lot. The fundamental properties of OO, C++ has. Now a case can be made that C++ is a bad OO language, at least for certain programming tasks. C++ has many disadvantages; it requires a large AmountOfTyping? to get anything done. And the low-level programming model makes it easy to shoot yourself in the foot. There are many things that I would much rather use Smalltalk, Java, Python, or something DotNet for. There are other programming tasks that C++ excels at that I wouldn't let any of the other languages anywhere near. But this has little if anything to do with OO.
I don't disagree with any of that, I believe in NygaardClassification, but my point was there is no one single definition that everyone accepts, so many form their own opinions about what constitutes OO. A Smalltalker is likely to have a vastly different opinion than a C++ programmer because of that environment. I'm not claiming they're right or wrong, just that it is quite understandable that they have different idea's of OOness. Smalltalk is pervasive with objects, far more so that C++, so regardless of the true definition of OO... Smalltalk is far more "something" than C++, most want to call that something OO.
A few people in the Smalltalk community seem to equate ObjectOriented with SmalltalkLanguage - and Smalltalk is one of the purest OO languages out there, so at first blush this is reasonable. But the error is the insistence that deviation from Smalltalk (or the Smalltalk way of doing things) implies deviation from OO. C++ deviates a hell of a lot from Smalltalk; BjarneStroustrup designed it that way. (Not that he thought Smalltalk was bad; however he was addressing a different problem-set). "If you want Smalltalk, use Smalltalk" is a common Stroustrup quote. But C++ is certainly capable of doing reasonable OO programming.
Many people making these arguments confuse SmalltalkLanguage with the combined language, IDE and application framework.
I've used a lot of different programming tools since starting OO development about 12 years ago. One of the best browsing and editing environments (ACI's Object Master) for C++ is no longer available - it used a Smalltalk-style 3 pane browser.
Currently I'm doing a lot of work in RealBasic which bundles an OO language with a clean cross-platform application framework (class Mac, OS/X, Windows and Linux) including graphics and sound. It reinforces for me the huge difference the application framework alone makes and how much value there is when the IDE knows the framework, not just the language. -- AndyDent