Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
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:
https://forums.macrumors.com/threads/246143/

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.

-Lee
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
so there's no benefit to studying C++ for mac programming? advancing from studying C to Objective-C is a good path to follow?

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.

-Lee
 

gnasher729

Suspended
Nov 25, 2005
17,980
5,566
so there's no benefit to studying C++ for mac programming? advancing from studying C to Objective-C is a good path to follow?

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++.
 

lee1210

macrumors 68040
Jan 10, 2005
3,182
3
Dallas, TX
do ruby and python have any advantages over cocoa?

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.

-Lee
 

kainjow

Moderator emeritus
Jun 15, 2000
7,958
7
do ruby and python have any advantages over cocoa?

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?
 

lazydog

macrumors 6502a
Sep 3, 2005
709
6
Cramlington, UK
so there's no benefit to studying C++ for mac programming? advancing from studying C to Objective-C is a good path to follow?

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
 

robbieduncan

Moderator emeritus
Jul 24, 2002
25,611
893
Harrogate
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?

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.
 

Darkroom

Guest
Original poster
Dec 15, 2006
2,445
0
Montréal, Canada
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.

-Lee

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?

that actually explains a lot... thanks...

and thanks for all the comments everyone.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.