John Lam 1997 — 2026

Observations on learning Cocoa

In between social engagements for the holidays, I’ve managed to finish James Duncan Davidson’s Learning Cocoa with Objective C book.

It’s a good first book on writing Cocoa applications, and will get you familiarized with Project Builder, Interface Builder and Objective C. It’s real strength lies in the fact that there are lots of “labs” in this book. Each chapter contains a self-contained application that you build by typing in code or following step-by-step instructions where Interface Builder is involved. This gives you a real sense of accomplishment and builds confidence as you tackle progressively more difficult projects.

It’s been such a long time since I’ve learned a new technology this way. When I was first learning C# / FCL, most of that involved writing command-line applications that explored various classes in the libraries. I have fond memories of dumping stack traces to the console window once I discovered the existence of the System.Diagnostics.StackTrace class.

These two approaches are dramatically different from each other. In the case of the CLR, I approached learning technologies from the “bottom up”. It was a long time before I looked at high-level technologies in the stack such as ASP.NET or Windows Forms. In the case of Cocoa, I’m definitely starting from the “top down”. I’m finding my way around an IDE (there was no IDE in the early days of the CLR), learning a new programming language, and learning a new class library.

I suspect the main reason why I am approaching learning OS X the way I am is that I don’t know how the underlying OS works. I don’t understand how code is packaged for execution, how it’s loaded, how processes are structured etc. I took for granted all of that knowledge when I approached learning the CLR for the first time. During that experience, I spent a lot of time thinking about “well Win32 does it this way, I wonder how the CLR does it?”

What I do know is that I need to be able to write some code to write test programs as I explore the frameworks. Since console applications are so 1970’s, I decided to learn enough about writing GUI applications using Cocoa to be dangerous. Once that has been established, I can revert to my time-honored techniques for spelunking in new territory. To be honest, I really should be writing console applications and exploring things from the ground up, but I just can’t resist that UI :)

Now that I’ve finished my first Cocoa book, I’m working my way through my second one: Simson Garfinkel and Michael Mahoney’s Building Cocoa Applications: A step-by-step guide. This is a much more detailed book than Davidson’s. In particular, Chapter 4 shows how to build a Cocoa application without using Interface Builder. This is extremely useful, since IB is a giant black box; it’s so important to be able to understand what IB generates for you.

A quick note: IB differs from Windows frameworks such as MFC or Windows Forms in that it doesn’t generate code. Instead, it appears to create various Cocoa framework objects at design time to express your user interface. Then when you are ready to write code, it serializes that object graph into a nib (NEXT Interface Builder) file that is then consumed by your Cocoa application. A nib to XML deserializer would be a really fun tool to write :)

1 archived reader comment

retrotron (2004-02-08)

As for nib to xml (or rather, maybe the reverse), there’s always Renaissance.