Carbon or Cocoa? Pros and Cons

Sage
Posts: 1,066
Joined: 2004.07
Post: #1
Which API is more useful for games, Carbon or Cocoa? What are the advantages and disadvantages of each?
Quote this message in a reply
Moderator
Posts: 1,560
Joined: 2003.10
Post: #2
Carbon and Cocoa are both perfectly usable for games. You're likely to hear mixed replies (or heated arguments) here of which one is better to use. My personal preference is Carbon, but I like Cocoa, too. Here are some points to consider when choosing which API to use:

- If you use Carbon, it is possible to compile the program as a PEF executable, which can be run on OS 9 and earlier (if that kind of thing matters to you), although if you do it this way, you can't use some of the newer, Mac OS X-only APIs in Carbon.

- Cocoa has the extra overhead of Objective-C messages instead of regular function calls, which can be 3-7 times slower. There are ways around that, but it's something to keep in mind.

- Cocoa tends to be more concise than Carbon. Something that takes 50 lines in Carbon might take only 20 in Cocoa. Cocoa is also generally easier to use, although this is not universally true.

- Carbon is a lower-level API than Cocoa. There are some things you can do in Carbon that can't be done in Cocoa. (But if you're writing in Cocoa, there's nothing stopping you from mixing in some Carbon to do what Cocoa can't.)

- Cocoa is amazingly well-designed. Every class I've used is very intuitive, and the documentation is pretty good. Carbon, however, has a few problems in places, and documentation is fairly non-existant for some parts of it.

- If you're using OpenGL for graphics, Cocoa and Carbon are approximately equal. If you're not, though, you can use either QuickDraw or Quartz for graphics. QuickDraw is older, and doesn't support some more advanced features such as alpha channel blending (although it's possible to fake it in QuickDraw), but it is pretty fast. Quartz is more heavy-duty, so it has more features, but is slower, probably too slow for an action game (but I could be wrong). Only Quartz is available in Cocoa. Both are available in Carbon.

- Due to the way Cocoa is set up, you can create your application's user interface with very little actual coding, using Interface Builder. It allows you to lay out windows, menus, buttons, etc., and set them up to send a particular message to your code when an event occurs. Interface Builder also works for Carbon applications, but you have to wire up the connections between the UI widgets and your code manually.

- Carbon code tends to be more portable than Cocoa code, as the Mac is really the only platform that uses Objective-C. (Not really an issue if it's a Mac-only application, though.)

So, in summary, use Carbon if you want raw speed or OS 9 support, and use Cocoa if you want a nice, easy-to-use, modern API. Or use a mixture, and get the ease of use of Cocoa with the speed of Carbon where it matters. The choice is up to you.

Hope that helped.

Alex Diener
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #3
Thanks for the help. That was a lot of good information. I think I'm leaning towards Carbon because I do need the speed and the Interface Builder is only good when creating windows with those specifically designed buttons, whereas my game might have a totally different setup for the user interface. I appreciate the responses I'm getting around this forum. Thanks.
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #4
How useful/pertinent is the source code from the book? Most of that stuff is pretty deprecated. I have the CD and could email you any or all of the source, but will it be that helpful?
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #5
I'm not sure how useful it will be now. I just thumbed through the book and I don't think I actually need to program anything out of the book. I think the knowledge of AI (as limited as it is presented in the book) was worth the small cost of the book. But thanks for the offer.
Quote this message in a reply
Member
Posts: 469
Joined: 2002.10
Post: #6
While Cocoa's message passing overhead is something to be considered, when it comes to games it's less of an issue. I generally do most of the pre-OpenGL graphics and metal-heavy stuff in CoreServices, Quartz Services, and CoreGraphics.

Cocoa also has the benefit of having slightly better memory management; handles are disgusting IMO. Actually, I dispise the entire Carbon Memory Manager.

While it's true Carbon is lower level than Cocoa, it's still no low enough to where you aren't going to be using lower-level frameworks anyways. You're likely to be falling back to HID, OpenGL, CoreAudio, and a lot of CoreServices and ApplicationServices junk whether you're using Cocoa or Carbon.

Lastly Cocoa is worlds easier to debug.

---Kelvin--
15.4" MacBook Pro revA
1.83GHz/2GB/250GB
Quote this message in a reply
Moderator
Posts: 102
Joined: 2003.07
Post: #7
I have the CD, You can e-mail me a time and I will .dmg it for you and send it to you via AIM if you want, or just email me and tell me what you want to do...

e-mail = carbonx@mail.xmission.com

-CarbonX
Quote this message in a reply
Member
Posts: 567
Joined: 2004.07
Post: #8
can you program COCOA with C?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #9
Nayr Wrote:can you program COCOA with C?
Nope, you must use Objective-C or Java.
Quote this message in a reply
Member
Posts: 370
Joined: 2002.04
Post: #10
Nayr Wrote:can you program COCOA with C?
Cocoa is an object-oriented framework (and C is not object-oriented), so probably not, and while there are bindings for other languages it makes little sense to program in C when you could use Objective-C.

Did you ever wonder why we had to run for shelter when the promise of a brave new world unfurled beneath the clear blue sky?
Quote this message in a reply
Member
Posts: 351
Joined: 2002.04
Post: #11
SimReality/Nick Wrote:I'm not sure how useful it will be now. I just thumbed through the book and I don't think I actually need to program anything out of the book. I think the knowledge of AI (as limited as it is presented in the book) was worth the small cost of the book. But thanks for the offer.

The discussion of different game types is still a very enlightening read despite being out-of-date. Great food-for-thought on the absolute fundamental of good game design - gameplay.
Quote this message in a reply
Sage
Posts: 1,066
Joined: 2004.07
Post: #12
So as a poll for everyone:
If you make games which API do you use and why?
Quote this message in a reply
Moderator
Posts: 608
Joined: 2002.04
Post: #13
You'll get a better response if you actually create a new thread with a poll. Smile
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Level editor creation - Cocoa or Carbon -Rice- 13 7,317 May 19, 2003 01:30 PM
Last Post: kattkieru
  Picking Cocoa or Carbon Muffinking 2 3,668 Jan 29, 2003 03:24 PM
Last Post: skyhawk