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

Top Mobile Game Discounts
Every day, we pick out a curated list of the best mobile discounts on the App Store and post them here. This list won't be comprehensive, but it every game on it is recommended. Feel free to check out the coverage we did on them in the links... | Read more »
Price of Glory unleashes its 1.4 Alpha u...
As much as we all probably dislike Maths as a subject, we do have to hand it to geometry for giving us the good old Hexgrid, home of some of the best strategy games. One such example, Price of Glory, has dropped its 1.4 Alpha update, stocked full... | Read more »
The SLC 2025 kicks off this month to cro...
Ever since the Solo Leveling: Arise Championship 2025 was announced, I have been looking forward to it. The promotional clip they released a month or two back showed crowds going absolutely nuts for the previous competitions, so imagine the... | Read more »
Dive into some early Magicpunk fun as Cr...
Excellent news for fans of steampunk and magic; the Precursor Test for Magicpunk MMORPG Crystal of Atlan opens today. This rather fancy way of saying beta test will remain open until March 5th and is available for PC - boo - and Android devices -... | Read more »
Prepare to get your mind melted as Evang...
If you are a fan of sci-fi shooters and incredibly weird, mind-bending anime series, then you are in for a treat, as Goddess of Victory: Nikke is gearing up for its second collaboration with Evangelion. We were also treated to an upcoming... | Read more »
Square Enix gives with one hand and slap...
We have something of a mixed bag coming over from Square Enix HQ today. Two of their mobile games are revelling in life with new events keeping them alive, whilst another has been thrown onto the ever-growing discard pile Square is building. I... | Read more »
Let the world burn as you have some fest...
It is time to leave the world burning once again as you take a much-needed break from that whole “hero” lark and enjoy some celebrations in Genshin Impact. Version 5.4, Moonlight Amidst Dreams, will see you in Inazuma to attend the Mikawa Flower... | Read more »
Full Moon Over the Abyssal Sea lands on...
Aether Gazer has announced its latest major update, and it is one of the loveliest event names I have ever heard. Full Moon Over the Abyssal Sea is an amazing name, and it comes loaded with two side stories, a new S-grade Modifier, and some fancy... | Read more »
Open your own eatery for all the forest...
Very important question; when you read the title Zoo Restaurant, do you also immediately think of running a restaurant in which you cook Zoo animals as the course? I will just assume yes. Anyway, come June 23rd we will all be able to start up our... | Read more »
Crystal of Atlan opens registration for...
Nuverse was prominently featured in the last month for all the wrong reasons with the USA TikTok debacle, but now it is putting all that behind it and preparing for the Crystal of Atlan beta test. Taking place between February 18th and March 5th,... | Read more »

Price Scanner via MacPrices.net

AT&T is offering a 65% discount on the ne...
AT&T is offering the new iPhone 16e for up to 65% off their monthly finance fee with 36-months of service. No trade-in is required. Discount is applied via monthly bill credits over the 36 month... Read more
Use this code to get a free iPhone 13 at Visi...
For a limited time, use code SWEETDEAL to get a free 128GB iPhone 13 Visible, Verizon’s low-cost wireless cell service, Visible. Deal is valid when you purchase the Visible+ annual plan. Free... Read more
M4 Mac minis on sale for $50-$80 off MSRP at...
B&H Photo has M4 Mac minis in stock and on sale right now for $50 to $80 off Apple’s MSRP, each including free 1-2 day shipping to most US addresses: – M4 Mac mini (16GB/256GB): $549, $50 off... Read more
Buy an iPhone 16 at Boost Mobile and get one...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering one year of free Unlimited service with the purchase of any iPhone 16. Purchase the iPhone at standard MSRP, and then choose... Read more
Get an iPhone 15 for only $299 at Boost Mobil...
Boost Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering the 128GB iPhone 15 for $299.99 including service with their Unlimited Premium plan (50GB of premium data, $60/month), or $20... Read more
Unreal Mobile is offering $100 off any new iP...
Unreal Mobile, an MVNO using AT&T and T-Mobile’s networks, is offering a $100 discount on any new iPhone with service. This includes new iPhone 16 models as well as iPhone 15, 14, 13, and SE... Read more
Apple drops prices on clearance iPhone 14 mod...
With today’s introduction of the new iPhone 16e, Apple has discontinued the iPhone 14, 14 Pro, and SE. In response, Apple has dropped prices on unlocked, Certified Refurbished, iPhone 14 models to a... Read more
B&H has 16-inch M4 Max MacBook Pros on sa...
B&H Photo is offering a $360-$410 discount on new 16-inch MacBook Pros with M4 Max CPUs right now. B&H offers free 1-2 day shipping to most US addresses: – 16″ M4 Max MacBook Pro (36GB/1TB/... Read more
Amazon is offering a $100 discount on the M4...
Amazon has the M4 Pro Mac mini discounted $100 off MSRP right now. Shipping is free. Their price is the lowest currently available for this popular mini: – Mac mini M4 Pro (24GB/512GB): $1299, $100... Read more
B&H continues to offer $150-$220 discount...
B&H Photo has 14-inch M4 MacBook Pros on sale for $150-$220 off MSRP. B&H offers free 1-2 day shipping to most US addresses: – 14″ M4 MacBook Pro (16GB/512GB): $1449, $150 off MSRP – 14″ M4... Read more

Jobs Board

All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.