TweetFollow Us on Twitter

Dec 01 Mac OS X 2

Volume Number: 17 (2001)
Issue Number: 12
Column Tag: Mac OS X

by Dan Wood, Alameda CA

The Tortoise and the Hare

Why Carbon Developers Should Start Learning Cocoa

We all know the fable about the tortoise and the hare. It can be interpreted many ways, but let’s say that it’s about the overconfident rabbit finding himself outpaced by the diligent tortoise.

Having returned from a week at WWDC, I am sad to report that there seems to be a tortoise-and-hare situation brewing in the Macintosh developer community.

In spite of the dominance of Windows and despite a recent economic slowdown, it was clear by looking at the crowds at WWDC that the Macintosh development community is alive and kicking. But let’s take a look at who is developing software for the Macintosh today. First off, you have the old-timers, the one who have been programming the Mac since the days of black/white screens and floppy disks. These guys can patch a trap in their sleep and understand the cosmic significance of Tech Note #31. But due to the acquisition of NeXT by Apple, there’s another group of developers that suddenly find themselves with a marketable skill set and a potential user base, and they were in force at the conference. (After all, the number of copies of Mac OS X sold to date has far surpassed the entire NeXT user base!) These weren’t the only kinds of developers at WWDC — after all, there were people who program in pure Java and are delighted to see a new platform for development and deployment, and there was a large WebObjects crowd as well. But on the desktop application development space, it was clear that there were two separate species — the Carbon-based life forms and the Cocoa-based life forms — and there wasn’t any camaraderie between them.

Two Frameworks

Apple has provided Mac OS X with two first-class frameworks for developing applications, Carbon and Cocoa. Carbon is an evolution of the procedural APIs for the Mac that date back to 1984. It’s the classic way of developing for the Mac, with a few twists to make programs run properly under Mac OS X as a first-class citizen. Cocoa is the object-oriented API for building Mac OS X that comes from OpenStep, which itself is descended from NeXTStep. And at WWDC, the Cocoa developers were outnumbered by the Carbon developers by a pretty big margin.

Perhaps there’s nothing inherently wrong with having two first-class APIs for programming a Macintosh. Nothing like this has ever succeeded before, though many (especially Apple) have tried. In general, an OS has always had a single dominant way of programming. Prior to Mac OS X, that dominant paradigm has been the Classic Macintosh Toolbox, programming in C++, using Metrowerks PowerPlant. So what’s the point of Apple trying to introduce a new framework (along with a new language, to boot) for development? Why is Apple trying to rock the boat? Are they just setting us developers up for a conflict?

Think Different

One thing that Apple has succeeded in doing over the last years has been surprising its detractors by creating amazing products. After the public had written off Apple for dead, here comes the iMac, the stylish G3 and G4, the drool-inducing Titanium PowerBook, killer apps such as iMovie and iTunes, and now an OS that pleases the crowds with Aqua and the geeks with its buzzword compliance and existing developers with its Carbon transition path

I’m going to go out on a limb by expressing the opinion that Cocoa is just such an amazing product, just one for developers. Trouble is, many Macintosh developers are going to have to “Think Different” if they are going to reap the benefits.

I feel qualified to express such an opinion because I straddle both worlds. I’ve been developing for the Mac since the screen was 512 pixels across. I’ve done my fair share of C++; I’ve written full-sized applications in PowerPlant, and I love MacsBug. But shortly after Apple acquired NeXT, I started learning Cocoa (or OpenStep or Yellow Box as it was called) and I started to, well, think different. I’ve since written a full-sized application in Cocoa. And frankly, I’m now spoiled: I don’t want to see another line of C++ again.

A Substantial Investment

Since I still have many friends and acquaintances in the “Carbon” camp, I am interested to hear what they think of Cocoa. It’s disheartening to hear how few of these folks express any desire to learn Cocoa. Some claim that they don’t like the syntax of Objective C. Others say that it’s too much of a learning curve. But I think that for the most part, it’s because long-time Mac developers have spent a long time investing in the Mac toolbox, and don’t want to see that expertise go to waste.

This makes a great deal of sense. After all, getting to know the intricacies of each manager in the Mac toolbox, along with the subtleties of C++ (a language that won’t stand still), learning and keeping up with PowerPlant, and tracking new APIs from Apple, is indeed a lot of effort over the years.

But perhaps a different approach would be to frame one’s expertise as owning a boat. Let’s say you like to race sailboats, and you have a boat that you bought 15 years ago. Every year you have to sink a substantial amount of money into maintaining it. One year, you have to overhaul the engine; another year there’s a leak to repair; perhaps the navigation system needs replacement. After fifteen years, you have a working boat, but you’ve sunk $100,000 into that boat over its lifetime. Somebody suggests you sell it and get a new boat, one that’s faster, more efficient, and less likely to need repair, but you’re going to resist it. After all, look at how much money you’ve spent on yours! And look at the new things you’ll have to learn to pilot and maintain the boat! That old boat will do just fine, thank you.

That kind of thinking may not be rational if you “do the math.” But it’s just as hard to let go of emotional investment as financial investment.

I view Cocoa as that new boat that traditional Mac developers are being offered. And it’s hard to let go of the years of honing your investment. And worst of all, I see a great community of Mac developers with “old boats” that are so immersed in their decision not to look at the new technology called Cocoa that they are going to find themselves the hares in the aforementioned fable.

Hare vs. Tortoise

Back to our Tortoise and Hare allegory. The tortoises, who have learned Cocoa — perhaps because they started out as NeXT developers, or perhaps because they had an open enough mind to try it out — have been quietly sneaking up with their shiny new boats made out of Cocoa. We haven’t quite reached this point yet, but I believe that the traditional Mac developers are going to find themselves “beaten” by the Cocoa developers — not in the sense of a one-on-one race, but in the marketplace. Why? Because once you have made the initial investment in learning Cocoa, the long and short of it is that it’s easier and faster to bring products to market.

Carbon’s advantages over Cocoa

Analogies are great, but they don’t work in real-world situations. And in the real world, there are lots of applications that need to be brought forward to Mac OS X. And Carbon is just the technology for that. Carbon means that you don’t have to throw away your code base and start over. Carbon means you can crank out new versions of your application in PowerPlant. Carbon means you get your application finished now instead of later. No learning of new languages or frameworks is required.

Cocoa’s advantages over Carbon

When you are starting to write any new application, however, you have to start designing and programming from ground zero. With Cocoa, ground zero is several floors above Carbon. Here is my take on why.

  • Already object-oriented. Rather than needing to graft a framework such as PowerPlant over a procedural API (while still leaving all the underpinnings fully exposed), Cocoa is object-oriented at the most fundamental level.
  • Heterogeneous data types. To represent a simple piece of data such as a string using C++ and PowerPlant and the Mac Toolbox, you may have to keep track of resources and pointers and handles, Pascal strings, null-terminated C strings, PowerPlant classes such as LStr255, C++ string objects, and so forth. Converting among all those types is half of your work! Cocoa has a string class called NSString. Other objects (such as dictionaries, numbers, booleans, colors, arbitrary data encapsulation, etc.) all have their own classes, and they all fit together in a modular fashion. You never have to parse through bits and bytes unless you’re reading a legacy data structure. Containers of objects contain other objects, enabling a complex structure can be read or written in a single line of code.
  • Easier language than C++. Learning Java or learning Objective C shouldn’t be that difficult for an experienced developer. And the syntax is so much simpler that you can probably get by without a “language lawyer” on staff to help you understand the subtle intricacies of C++. To quote Tom Cargil from the C++ Journal, “If you think C++ is not overly complicated, just what is an abstract virtual base pure virtual private destructor, and when was the last time you needed one?”
  • More Object-Oriented than C++. While C++ has the object-oriented properties of inheritance, polymorphism, and encapsulation, what is lacks is dynamism. With Objective-C (and, to some extent, Java), you can send an arbitrary message to an arbitrary object. The “fragile base class” problem of C++ does not exist in Objective C. Most of the classes in Cocoa take advantage of this, making it very easy build an application.
  • No more “hookup” code. Even with the aid of a C++ framework like PowerPlant, much code needs to be written to access the user interface from the code (e.g. FindPaneByID()) and to dispatch user input to the code via switch() statements. In Cocoa, you hook up the code to the UI using Interface Builder. No code is written or generated, meaning significantly smaller programs.
  • Flatter Class Hierarchy. Because of the dynamic nature of Objective C and the notion of delegation, the class hierarchy of Cocoa is extremely flat. Your applications rarely need to subclass Cocoa classes. The delegation model of Cocoa emphasizes cooperation between classes rather than extension of existing classes. By avoiding subclassing, your objects avoid having to know about the workings of their parent class.
  • Gestalt. No, I’m not talking about an API for querying a Mac’s capabilities. All of the above reasons combined, somehow, make up an experience for the developer that is more than just their sum. Simple applications in Cocoa are just that — simple. Complex applications are possible and surprisingly manageable.

The Finish Line?

There is no real finish line; Cocoa and Carbon will continue to exist for some time. Each has their advantages, but Carbon is the winner when there are business reasons; Cocoa is the winner when there are technical reasons. As time goes on, the business advantages of Carbon will fade away, and the market for Cocoa programmers will be larger than the market for Carbon programmers. The developers that insist on defending their investment in Carbon avoid Cocoa when it comes time to build new projects may find that the Cocoa developers have beaten them to market. I hope that this doesn’t happen. If you are a carbon developer, start learning Cocoa in your spare time — Pick up the new Learning Cocoa book from O’Reilly and try it out. The smartest developers in the world are Mac developers — Imagine how much better off we will all be if they can leverage Cocoa.


Dan Wood is a long-time Macintosh developer who started learning about Mac OS X technologies immediately after Apple acquired NeXT. He has programmed for the Mac using Forth, Pascal, Scheme, 680x0 assembly, C, C++, Java, and Objective-C, using object frameworks such as Think Class Library, Metrowerks PowerPlant, Swing, and Cocoa. You can reach him at dwood@karelia.com.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Latest Forum Discussions

See All

The Legend of Heroes: Trails of Cold Ste...
I adore game series that have connecting lore and stories, which of course means the Legend of Heroes is very dear to me, Trails lore has been building for two decades. Excitedly, the next stage is upon us as Userjoy has announced the upcoming... | Read more »
Go from lowly lizard to wicked Wyvern in...
Do you like questing, and do you like dragons? If not then boy is this not the announcement for you, as Loongcheer Game has unveiled Quest Dragon: Idle Mobile Game. Yes, it is amazing Square Enix hasn’t sued them for copyright infringement, but... | Read more »
Aether Gazer unveils Chapter 16 of its m...
After a bit of maintenance, Aether Gazer has released Chapter 16 of its main storyline, titled Night Parade of the Beasts. This big update brings a new character, a special outfit, some special limited-time events, and, of course, an engaging... | Read more »
Challenge those pesky wyverns to a dance...
After recently having you do battle against your foes by wildly flailing Hello Kitty and friends at them, GungHo Online has whipped out another surprising collaboration for Puzzle & Dragons. It is now time to beat your opponents by cha-cha... | Read more »
Pack a magnifying glass and practice you...
Somehow it has already been a year since Torchlight: Infinite launched, and XD Games is celebrating by blending in what sounds like a truly fantastic new update. Fans of Cthulhu rejoice, as Whispering Mist brings some horror elements, and tests... | Read more »
Summon your guild and prepare for war in...
Netmarble is making some pretty big moves with their latest update for Seven Knights Idle Adventure, with a bunch of interesting additions. Two new heroes enter the battle, there are events and bosses abound, and perhaps most interesting, a huge... | Read more »
Make the passage of time your plaything...
While some of us are still waiting for a chance to get our hands on Ash Prime - yes, don’t remind me I could currently buy him this month I’m barely hanging on - Digital Extremes has announced its next anticipated Prime Form for Warframe. Starting... | Read more »
If you can find it and fit through the d...
The holy trinity of amazing company names have come together, to release their equally amazing and adorable mobile game, Hamster Inn. Published by HyperBeard Games, and co-developed by Mum Not Proud and Little Sasquatch Studios, it's time to... | Read more »
Amikin Survival opens for pre-orders on...
Join me on the wonderful trip down the inspiration rabbit hole; much as Palworld seemingly “borrowed” many aspects from the hit Pokemon franchise, it is time for the heavily armed animal survival to also spawn some illegitimate children as Helio... | Read more »
PUBG Mobile teams up with global phenome...
Since launching in 2019, SpyxFamily has exploded to damn near catastrophic popularity, so it was only a matter of time before a mobile game snapped up a collaboration. Enter PUBG Mobile. Until May 12th, players will be able to collect a host of... | Read more »

Price Scanner via MacPrices.net

Sunday Sale: Apple Studio Display with Standa...
Amazon has the standard-glass Apple Studio Display on sale for $300 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1299.97 $300 off MSRP For the latest prices and... Read more
Apple is offering significant discounts on 16...
Apple has a full line of 16″ M3 Pro and M3 Max MacBook Pros available, Certified Refurbished, starting at $2119 and ranging up to $600 off MSRP. Each model features a new outer case, shipping is free... Read more
Apple HomePods on sale for $30-$50 off MSRP t...
Best Buy is offering a $30-$50 discount on Apple HomePods this weekend on their online store. The HomePod mini is on sale for $69.99, $30 off MSRP, while Best Buy has the full-size HomePod on sale... Read more
Limited-time sale: 13-inch M3 MacBook Airs fo...
Amazon has the base 13″ M3 MacBook Air (8GB/256GB) in stock and on sale for a limited time for $989 shipped. That’s $110 off MSRP, and it’s the lowest price we’ve seen so far for an M3-powered... Read more
13-inch M2 MacBook Airs in stock today at App...
Apple has 13″ M2 MacBook Airs available for only $849 today in their Certified Refurbished store. These are the cheapest M2-powered MacBooks for sale at Apple. Apple’s one-year warranty is included,... Read more
New today at Apple: Series 9 Watches availabl...
Apple is now offering Certified Refurbished Apple Watch Series 9 models on their online store for up to $80 off MSRP, starting at $339. Each Watch includes Apple’s standard one-year warranty, a new... Read more
The latest Apple iPhone deals from wireless c...
We’ve updated our iPhone Price Tracker with the latest carrier deals on Apple’s iPhone 15 family of smartphones as well as previous models including the iPhone 14, 13, 12, 11, and SE. Use our price... Read more
Boost Mobile will sell you an iPhone 11 for $...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering an iPhone 11 for $149.99 when purchased with their $40 Unlimited service plan (12GB of premium data). No trade-in is required... Read more
Free iPhone 15 plus Unlimited service for $60...
Boost Infinite, part of MVNO Boost Mobile using AT&T and T-Mobile’s networks, is offering a free 128GB iPhone 15 for $60 per month including their Unlimited service plan (30GB of premium data).... Read more
$300 off any new iPhone with service at Red P...
Red Pocket Mobile has new Apple iPhones on sale for $300 off MSRP when you switch and open up a new line of service. Red Pocket Mobile is a nationwide MVNO using all the major wireless carrier... Read more

Jobs Board

Licensed Practical Nurse - Womens Imaging *A...
Licensed Practical Nurse - Womens Imaging Apple Hill - PRN Location: York Hospital, York, PA Schedule: PRN/Per Diem Sign-On Bonus Eligible Remote/Hybrid Regular Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
Operating Room Assistant - *Apple* Hill Sur...
Operating Room Assistant - Apple Hill Surgical Center - Day Location: WellSpan Health, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Read more
Solutions Engineer - *Apple* - SHI (United...
**Job Summary** An Apple Solution Engineer's primary role is tosupport SHI customers in their efforts to select, deploy, and manage Apple operating systems and Read more
DMR Technician - *Apple* /iOS Systems - Haml...
…relevant point-of-need technology self-help aids are available as appropriate. ** Apple Systems Administration** **:** Develops solutions for supporting, deploying, Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.