Friday, July 17, 2009

Back in the Objective-C Saddle Again

Every year or so I decide to tackle Objective-C and Cocoa again, partly because I want to create useless applications for my computer, but mainly as a brain-sharpening mental exercise.

A few things have hindered me:

* An incomplete mastery of C.

* Textbooks which tell you to do things, but don't explain why.

* Textbooks which go out of date with each OS X update.

For these reasons I've bumbled around the language, eventually finding myself out of my depth and retreating to safer pursuits (like YouTube puppet shows with a seal, for example).

This time I think I'm REALLY getting somewhere. Part of my success is due to my previous attempts at learning the concepts -- even when I failed I took away some valuable lessons -- but I'm using some different resources now...ones that suit my knowledge level AND my method of learning.

I started with Stephen G. Kochan's "Programming in Objective-C." Whereas most other books either assume a total knowledge of C or a complete LACK of knowledge, Kochan's book is written for those who understand the concepts but REALLY need a syntax refresher. The first half explains all the elements of C in an Objective-C context, and ends with "Underlying C Language Features" (like structs and character arrays) that you'll probably never need (but should know about anyway).

The second half of the book is devoted to using the essential Objective-C Foundation classes -- numbers, strings, files, etc. -- and all the important methods. Once you've finished "Programming in Objective-C" you are ready for the Cocoa concepts.

That's where Aaron Hillegass' celebrated "Cocoa Programming for Mac OS X" comes in. This book assumes a comfortable knowledge of both C and Objective-C, and it teaches you how to use them effectively with Interface Builder. By page 100 you're building full-featured applications for your Mac...

...but Hillegass' book is more of a "gentle introduction" than I prefer; it often skips over the lower level "HOW does this work?" stuff. If you're like me then you NEED that information, so I recommend that you SIMULTANEOUSLY read "Cocoa Design Patterns" by Erik M. Buck and Donald A. Yacktman. By teaching you the best ways to use the extremely flexible NEXTSTEP frameworks -- and revealing the common patterns that developers use when writing Cocoa applications -- you learn exactly why Hillegass tells you to -- for instance -- [[foo alloc] init].

The only downside of "Cocoa Design Patterns" is that it's still unfinished. I bought a "rough cut" advance copy and it is teaching me SO MUCH...but it's damn obnoxious to read, full of spelling mistakes, incorrect cross-references, incomprehensible formatting, and half-finished ideas. It's very much a work in progress -- and it's advertised as such, so I wasn't ripped off -- but you MIGHT want to wait until the book is actually released.

These three books are my recommended recipes for success. They teach you the syntax, the application, and the structure of Cocoa programming. They also teach you why creating Mac applications is such a pleasure...until you start doing reference counting, of course.

No comments: