Separate names with a comma.
Discussion in 'Mac Programming' started by Darkroom, Sep 12, 2008.
... between C++ and Objective-C? if so, what are their differences?
Yes. They are entirely different languages with different syntax, compilers, "standard" libraries and capabilities. I can't even thing where to start listing the differences as they are not related to each other by much more than both being based off C (although Objective-C is a strict C superset and C++ isn't) and both being object oriented.
One of the major ones is that C++ supports multiple inheritance while Objective-C does not.
And Objective-C has categories which C++ doesn't.
Edit to add: This question is a bit like saying "I'm an English speaker. Are French and German the same?"
I could be quite pedantic with that but I'll save it for myself .
You are most kind!
What? And deprive of us of a tiny amount of amusement or interest late on a Friday afternoon? I say post it...
To confuse things further, you can mix Objective-C and C++ (this is generally referred to as Objective-C++).
We have had many (sometimes heated) discussions about Objective-C and C++ here, the most prolific of which is here:
I won't have too much to add to what people have already stated, but at the basest level the languages are related only in-so-far as they were based (to different degrees) on C. If you look at a routine dealing with primitives (and structs, which I would consider primitive) in C++ and Objective-C they will look similar, but if you look at something dealing with either language's object models, they will look totally different (although now, with the ability to access properties in Objective-C 2.0 using dot notation, that would look a little more similar).
I guess to speak in broad terms, the main differences are the object models. Most of the major differences come from how objects are defined, how their properties are accessed, how their behaviors/functions/methods are invoked, inheritance models, abstract objects vs. protocols, etc. Other "smaller" differences like operator precedence are really differences in C and C++, and that difference was just inherited from C by Objective-C.
Hey, for some of us it's the middle of the morning!
Sorry, I'm going home in 5 minutes
so there's no benefit to studying C++ for mac programming? advancing from studying C to Objective-C is a good path to follow?
That's basically correct yes. Although if you are looking at the wider world C++ is use a lot more than Objective-C.
Cocoa is the chosen path going forward, so Objective-C it is. If you want to branch out Apple seems to have blessed python and ruby by providing a Cocoa bridge in Leopard, making them "first class" languages on OS X. If you just interested in diversifying and getting experience with a different language, one of those might be good.
do ruby and python have any advantages over cocoa?
There isn't "no benefit". Let's say you learned C. Most things you learned in C are useful in C++ and Objective-C as well. Then at some point you'd need to learn about object-oriented programming. You could learn Objective-C, or C++, or Java (with Java, the C knowledge is less helpful). You learn two things: The syntax of the language, and the concepts of object-oriented programming. If you know object-oriented programming, then learning to use either C++ or Objective-C in a useful way is much easier.
There is also the question whether you are going to share code between a Macintosh and a non-Macintosh application. In that case it is likely that the user interface on the Mac is written with Cocoa in Objective-C, and the Linux or Windows user interface is written with different libraries in a different language. However, a lot of the code that does the actual work could be written in a different language, for example C++.
Cocoa is an Objective-C API, not a language. As of Leopard you can now access the Cocoa API from python or ruby.
I don't consider any language superior to any other. The only comparison is for the task at hand. If you're doing something that is well-suited to Objective-C, use that. If you're doing something well-suited to python or ruby, or you are more comfortable performing the task with those tools, go for it.
Ruby/Python are languages. Cocoa is a library of code accessible via Objective-C, but you can also access it via Ruby and Python (and others) in Leopard (and in Tiger via third-parties).
C++ is still useful if you're doing Mac programming. A lot of open source code you may want to use is written in C++. Also a lot of older programs for the Mac still use C++ underneath. Also it's great for writing cross platform code. Put most of your logic in C++ and write native UI wrappers around it.
I will say though, I see more C code than C++. I'm not really sure why that is. Anyone want to give some insight into that?
I think I have to disagree with the others on this
if you know C++ then you'll appreciate how powerful Objective-C++ is/can be. But if you don't already know C++ then I would steer clear, at least until you've learned Objective-C.
b e n
In library code or self-contained in applications. It makes sense for libraries as C is a kind of lowest common denominator: you can call C libraries from almost any language. Not really so of C++ libraries.
Self contained in apps is harder to explain. I think it's possible because a lot of the more old-school programmers learnt C and then picked up C++ afterwards and the old C habits die hard. So you end up seeing C++ that is really more like procedural C.
that actually explains a lot... thanks...
and thanks for all the comments everyone.