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

Whitethorn Games combines two completely...
If you have ever gone fishing then you know that it is a lesson in patience, sitting around waiting for a bite that may never come. Well, that's because you have been doing it wrong, since as Whitehorn Games now demonstrates in new release Skate... | Read more »
Call of Duty Warzone is a Waiting Simula...
It's always fun when a splashy multiplayer game comes to mobile because they are few and far between, so I was excited to see the notification about Call of Duty: Warzone Mobile (finally) launching last week and wanted to try it out. As someone who... | Read more »
Albion Online introduces some massive ne...
Sandbox Interactive has announced an upcoming update to its flagship MMORPG Albion Online, containing massive updates to its existing guild Vs guild systems. Someone clearly rewatched the Helms Deep battle in Lord of the Rings and spent the next... | Read more »
Chucklefish announces launch date of the...
Chucklefish, the indie London-based team we probably all know from developing Terraria or their stint publishing Stardew Valley, has revealed the mobile release date for roguelike deck-builder Wildfrost. Developed by Gaziter and Deadpan Games, the... | Read more »
Netmarble opens pre-registration for act...
It has been close to three years since Netmarble announced they would be adapting the smash series Solo Leveling into a video game, and at last, they have announced the opening of pre-orders for Solo Leveling: Arise. [Read more] | Read more »
PUBG Mobile celebrates sixth anniversary...
For the past six years, PUBG Mobile has been one of the most popular shooters you can play in the palm of your hand, and Krafton is celebrating this milestone and many years of ups by teaming up with hit music man JVKE to create a special song for... | Read more »
ASTRA: Knights of Veda refuse to pump th...
In perhaps the most recent example of being incredibly eager, ASTRA: Knights of Veda has dropped its second collaboration with South Korean boyband Seventeen, named so as it consists of exactly thirteen members and a video collaboration with Lee... | Read more »
Collect all your cats and caterpillars a...
If you are growing tired of trying to build a town with your phone by using it as a tiny, ineffectual shover then fear no longer, as Independent Arts Software has announced the upcoming release of Construction Simulator 4, from the critically... | Read more »
Backbone complete its lineup of 2nd Gene...
With all the ports of big AAA games that have been coming to mobile, it is becoming more convenient than ever to own a good controller, and to help with this Backbone has announced the completion of their 2nd generation product lineup with their... | Read more »
Zenless Zone Zero opens entries for its...
miHoYo, aka HoYoverse, has become such a big name in mobile gaming that it's hard to believe that arguably their flagship title, Genshin Impact, is only three and a half years old. Now, they continue the road to the next title in their world, with... | Read more »

Price Scanner via MacPrices.net

B&H has Apple’s 13-inch M2 MacBook Airs o...
B&H Photo has 13″ MacBook Airs with M2 CPUs and 256GB of storage in stock and on sale for up to $150 off Apple’s new MSRP, starting at only $849. Free 1-2 day delivery is available to most US... Read more
M2 Mac minis on sale for $100-$200 off MSRP,...
B&H Photo has Apple’s M2-powered Mac minis back in stock and on sale today for $100-$200 off MSRP. Free 1-2 day shipping is available for most US addresses: – Mac mini M2/256GB SSD: $499, save $... Read more
Mac Studios with M2 Max and M2 Ultra CPUs on...
B&H Photo has standard-configuration Mac Studios with Apple’s M2 Max & Ultra CPUs in stock today and on Easter sale for $200 off MSRP. Their prices are the lowest available for these models... Read more
Deal Alert! B&H Photo has Apple’s 14-inch...
B&H Photo has new Gray and Black 14″ M3, M3 Pro, and M3 Max MacBook Pros on sale for $200-$300 off MSRP, starting at only $1399. B&H offers free 1-2 day delivery to most US addresses: – 14″ 8... Read more
Department Of Justice Sets Sights On Apple In...
NEWS – The ball has finally dropped on the big Apple. The ball (metaphorically speaking) — an antitrust lawsuit filed in the U.S. on March 21 by the Department of Justice (DOJ) — came down following... Read more
New 13-inch M3 MacBook Air on sale for $999,...
Amazon has Apple’s new 13″ M3 MacBook Air on sale for $100 off MSRP for the first time, now just $999 shipped. Shipping is free: – 13″ MacBook Air (8GB RAM/256GB SSD/Space Gray): $999 $100 off MSRP... Read more
Amazon has Apple’s 9th-generation WiFi iPads...
Amazon has Apple’s 9th generation 10.2″ WiFi iPads on sale for $80-$100 off MSRP, starting only $249. Their prices are the lowest available for new iPads anywhere: – 10″ 64GB WiFi iPad (Space Gray or... Read more
Discounted 14-inch M3 MacBook Pros with 16GB...
Apple retailer Expercom has 14″ MacBook Pros with M3 CPUs and 16GB of standard memory discounted by up to $120 off Apple’s MSRP: – 14″ M3 MacBook Pro (16GB RAM/256GB SSD): $1691.06 $108 off MSRP – 14... Read more
Clearance 15-inch M2 MacBook Airs on sale for...
B&H Photo has Apple’s 15″ MacBook Airs with M2 CPUs (8GB RAM/256GB SSD) in stock today and on clearance sale for $999 in all four colors. Free 1-2 delivery is available to most US addresses.... Read more
Clearance 13-inch M1 MacBook Airs drop to onl...
B&H has Apple’s base 13″ M1 MacBook Air (Space Gray, Silver, & Gold) in stock and on clearance sale today for $300 off MSRP, only $699. Free 1-2 day shipping is available to most addresses in... Read more

Jobs Board

Senior Product Associate - *Apple* Pay (AME...
…is seeking a Senior Associate of Digital Product Management to support our Apple Pay product team. Labs drives innovation at American Express by originating, Read more
Medical Assistant - Surgical Oncology- *Apple...
Medical Assistant - Surgical Oncology- Apple Hill Location: WellSpan Medical Group, York, PA Schedule: Full Time Sign-On Bonus Eligible Remote/Hybrid Regular Apply Read more
Omnichannel Associate - *Apple* Blossom Mal...
Omnichannel Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
Cashier - *Apple* Blossom Mall - JCPenney (...
Cashier - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Blossom Mall Read more
Operations Associate - *Apple* Blossom Mall...
Operations Associate - Apple Blossom Mall Location:Winchester, VA, United States (https://jobs.jcp.com/jobs/location/191170/winchester-va-united-states) - Apple Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.