I've seen this argument all over. how C++ isn't a "real" OO Language. I hear about how it doesn't have certain features, or how it's poorly designed... the FQA is a frequent reply to my insistence that C++ is indeed a good language for OO programming. But I as a programmer (I've been writing code since I was 12) I want to go on record and say a few things:
Yes, C++ is a real OO language. It isn't dynamically typed though. That makes some things possible in a dynamically typed language harder to do in C++. Cocoa/AppKit takes advantage of informal protocols and other aspects of Objective-C which are harder to implement in C++ (not impossible, just harder).
1: why the hell would anyone want to create an array that consisted of a set of completely different objects? I mean that has to be the most piss poor technique I've ever seen. arrays are for collecting a group of similar objects together for quick access in an incremental list. Consider the following:
Given that C is an array, what is it an array of.... if you say, it's an array of a bunch of things then that begs the question: well, why are they together? why didn't you group them in a structure, why did you make an array out of them? I can think of no useful, scalable, understandable design that would require a single array that can contain a multitude of types. there's simply no reason for the feature.
Formal or informal protocols can be a way to group objects together in a way that makes sense. In a strongly typed language, informal protocols don't exist. Formal protocols have to be handled as abstract or virtual types, but can still be used in templates.
In Objective-C, grouping objects that follow an informal protocol is more interesting. And really, using an NSArray of NSObjects makes more sense in Objective-C, where you don't even have a concept of templates. You can't have a write-once, use-everywhere generic collection without either templates (C++) or using a single base type (Objective-C / Cocoa). I can think of a couple times where I used a collection of objects that were grouped because of their informal protocol, rather than their type.
2: Objective C is a hodgepodge! I don't know what any programmer sees in it, it's like the girl who likes the deadbeat guy and the C++ programmers are trying to tell these girls that that guy isn't right for them that he sucks but they won't listen and instead bring up the C++ programmer's personal weaknesses. I've yet to hear any compelling reason (except that cocoa tries to force you to be able to program it) to abandon all my C++ knowledge, limit it to standard C, and the God aweful smalltalk extensions. ironically the pisspoor code of old old K and R C being compatable is considered a primary advantage of Obj-C over C++.... there's a reason that code doesn't work in C++... it's so poorly written that it sucks at least in one way and most likely in many others. If you don't think it's a hodgepodge, then consider the following: <snipped for sanity>
A couple things to mention:
- A message may syntactically seem like an object method, but it behaves in a way that isn't always intuitive. It really winds up doing a vtable dispatch based on the object, and dispatches it if possible, otherwise it throws an exception. C/C++ doesn't allow this sort of ad-hoc resolving of symbols, C/C++ requires a function pass muster at compiletime, not runtime.
- Objective-C was designed at a time before the concept of what makes a language stabilized into "it should be C". Back in the era where a language simply was what the designer(s) felt was best for it.
So yes, Objective-C is a hodgepodge, and maybe not the ideal in terms of syntax. That isn't to say C is ideal either, but I am not going to disagree that Objective-C feels like a second language slapped onto a first.
So what now? I think a wrapper library needs to be written.... at least a wrapper library, if not a set of bindings for obj c.
Because of the differences in how things get typed in C++ versus Obj-C, bindings will be tricky. A wrapper library should be possible, but it would be expensive to maintain outside of Apple doing it themselves.
Or cocoa needs to be hacked and reimplemented in C++. I've yet to hear a valid argument against C++ that stood up to scrutiny. the worst is that C++ compiles slower to accomodate for code ambiguities that depend on context. that's great! C++ isn't perfect but it doesn't have to be.
There are some things that Apple currently relies on in the core of AppKit that requires a dynamically typed language. While it would be possible to port most of this to C++, it would be a big effort. Cocoa came into being because it already existed on NeXTStep, not because it was new. Apple wanted a more modern API in OS X, and they had this mostly-complete API in the form of the NeXTStep APIs. It allowed Apple to push a modernized API set to their new platform faster than it would have been otherwise.
They just haven't been willing to spend the manpower required to port the whole API set over. And if they had decided to continue to maintain Carbon for 64-bit, that was supposed to be their C/C++ API for developers, rather than Cocoa (using CoreServices as a shared C foundation that both built up on).
And I will say that I have chunks of code that would not work without major restructuring in C++. Of course, I have code which abuses Objective-C specific functionality (like introspection, and KVC is a great little piece of tech to play with), which is why it doesn't port easily.
And really, my only argument against a C++ version of Cocoa? It wouldn't be Cocoa. It would be like Cocoa, but it wouldn't be Cocoa. A fair number of the Obj-C oriented technologies don't make sense in a statically typed language, and would behave and be implemented differently. Although big chunks would remain fairly similar. What OS X needs is a good C++ oriented API. It doesn't have to be based on Cocoa directly, because some of the concepts don't work in both places, and I don't think that it would be bad if a C++ API set was designed with slightly different goals in mind.