views:

547

answers:

4

Why did Apple decide to use Objective-C for the iPhone SDK and not C++?

It seems strange to me that they would not have chosen a language more popular than Objective-C. Is it because wanted to have something unique in their application which is not otherwise in general use?

I'm just curious about this.

+3  A: 

It's because Objective C has been the de facto language for Mac OS X development before it was Mac OS X. When Jobs left Apple to set up NeXT, the language Objective C was developed as a specific language that wasn't C++ and avoided many of its pitfalls. It therefore makes sense that any portable or consumer equipment (including Apple TV) use Objective C as their primary development language, and dropping down to the underlying C layer when needed for performance or interface issues.

AlBlue
Objective-C was around well before NeXT. They just made it popular.
Kendall Helmstetter Gelner
+2  A: 

Objective-C adds object oriented programming to C. It was used for NeXT, upon which a lot of OSX is derived. It supports all of C, and is simpler than C++.

http://discussions.apple.com/thread.jspa?threadID=2091191

The Matt
+19  A: 

Apple merged with NeXT in the '90s and Mac OS X was made from NeXT's operating system, NeXTSTEP. Objective-C was the official language of NeXTSTEP's application frameworks, which became Mac OS X's Cocoa. Mac OS X was then adapted into the iPhone OS, and Cocoa was made into Cocoa Touch. Objective-C has held up pretty well all along the way, and a lot of Cocoa's features would be difficult to translate into C++.

So essentially, it all comes from NeXT.

Chuck
Some history. Read page 1 from http://www.amazon.com/gp/reader/0321503619/ref=sib_dp_ptu#reader-link
epatel
Dead on. Note that an attempt was made to bridge Cocoa to Java, but the dynamic features just don't translate well, and CocoaJava was deprecated in 10.4 and will be gone in 10.6+. Porting to C++ would face similar problems, and the only thing it would really "solve" is developer familiarity with the programming language. C++ is a vastly complex language, and while Objective-C isn't perfect, it does have plenty of its own advantages, and compares favorably with C++ and other OO languages in many respects.
Quinn Taylor
I think a Cocoa-C++ bridge would actually be harder than Cocoa-Java. Java itself was strongly influenced by Objective-C, so there are more similarities there than between two completely unrelated languages like C++ and Objective-C.
Chuck
There is in fact Objective C++, which is needed when compiling Objective C code with C++ programs. It's fairly rarely used, but the manpages for gcc uses .M or .mm files to indicate Objective C++ code.
AlBlue
@AlBlue: That just lets you embed C++ in Objective-C. You still have to use Objective-C to use Cocoa features.
Chuck
+1  A: 

Note that Objective-C is not a new language. It's been around since 1986 - well before Java or C#!

It has been in general use ever since NeXT, many real-world applications are around that make use of it.

Kendall Helmstetter Gelner