views:

773

answers:

3

I see a lot of debate going back and forth on which language to use to develop real-time 3D games, and the general consensus is that C or C++ are the only languages that can offer suitable performance for high-end, system-intensive 3D games. I see a lot of people saying C#, Java or Python are too slow, particularly because of garbage collection. How about Objective C? Does Objective C have automatic garbage collection? What besides Automatic Garbage Collection make a language 'too slow' or unsuited for 3D games?

This question is probably more of a 'thought experiment' since I doubt I'll ever develop a game that is so resource heavy that these questions need to be addressed, but being a programmer, I'm inexplicably obsessed with performance, so I'd still like to know just for my own jollies.

+6  A: 

Objective-C 2.0 has garbage collection available on Mac OS X 10.5, but it is optional -- you can still compile Objective-C apps without garbage collection if you so choose. On other platforms (iPhone, Mac OS X pre-10.5, and anything else), there is no garbage collection, and you have to manually manage your memory.

Objective-C is a strict superset of C, so you can code plain C in Objective-C if you want. Hence, there's no reason not to use Objective-C for games that wouldn't also apply to using C. You can use the extra features Objective-C provides as much or as little as you want.

Adam Rosenfield
A: 

Objective-C does not have automatic garbage collection. Java has various methods of garbage collection and some of them are designed to be compatible with games by occurring incrementally at regular intervals. I would be surprised if C# or anything else which also had garbage collection didn't have multiple methods to choose from, some of which are compatible with games.

The only thing off the top of my head that would might make a game unsuitable for 3D games would be if it were interpreted and particularly slow in its implementation. That's not a characteristic of anything you listed above.

P.S. To address your original question, I'm pretty sure anyone who has an iPod Touch or iPhone will be able to tell you that Objective-C is definitely up to 3D games :)

John Munsch
It wasn't me, but I'm pretty sure the downvotes are because Objective-C on Mac OS X does, in fact, have automatic garbage collection. It's optional, but it is there. Just FYI, because I hate downvotes that don't educate.
Chuck
And the Mac is the only platform for Objective-C, right. Uh, no. It's not. The device I have sitting right in front of me has Objective-C and no automatic garbage collection. Plus, he's asking if Objective-C has garbage collection because he's concerned whether or not it would cause bursty performance and make it a poor choice for a 3D game. It doesn't. Not in any way that would require its use. Did nobody but me read what he said?
John Munsch
The Mac is the primary platform for Objective-C. Making a blanket claim about Objective-C that is not true of the Mac is like making a blanket claim about computers that isn't true of Windows. "Computers are not capable of running graphics programs." Well, sure, some aren't — I have one right in the room here — but I still don't think it's a true statement.
Chuck
+5  A: 

The only real slowdown with Objective-C itself would be the messaging mechanism—and even then, it's usually components of the Cocoa framework that would slow things down. Objective-C's message sending doesn't really hurt performance that much.

Anyways, for most games, the majority of the performance bottlenecks will come from graphics code: if you delegate graphics stuff to OpenGL, which is ridiculously fast, then there really should be no problem with using Objective-C for games. The only other place where I can see Objective-C or Cocoa providing bottlenecks would be for intensive physics code—and that should probably be written in pure C/C++ anyways. Everything else, though, shouldn't really matter that much.

To be honest, I'd wager that the majority of OS X games nowadays are written in Objective-C using the Cocoa frameworks, with the performance-sensitive code written in pure C/C++ (and with graphics code utilizing OpenGL).

htw