Help a 98 lb weakling develop into a Mac programmer with Cocoa-fu.
September 22, 2005 4:05 PM   Subscribe

I would like to learn to program for Mac OS X, and Cocoa seems to be the way to go. Considering most of the documentation and books I've picked up say things like, "since this book is about Cocoa, we assume you know Objective-C," and the Objective-C books assume I already know C... What's the best path for a beginner like myself to progress from knowing nothing, to actually programming using Cocoa on Mac OS X?

I did some BASIC programming on my ATARI 800, and later in high school, but that was more than a decade ago. So, I understand some basic programming concepts, but anything beyond that, treat me as a newbie. An additional consideration-- if I'm only going to be using Objective-C, is there any resource that will teach me that language as a whole without mucking about with the parts of ANSI-C I'll never use? ...or is that not a good way to go?
posted by mboszko to Computers & Internet (23 answers total) 17 users marked this as a favorite
Best answer: I'm sure you'll get opinions on both sides of this issue, but I'd encourage you to start your journey with just Objective C, your favorite text editor, and the command line. Kochan's Programming in Objective-C book takes this approach; I'm sure you've seen it, it's one of the standards.

Kochan's book is supposed to be self-contained, but inevitably there's a tiny amount of assumed knowledge that creeps in. Don't worry, you can pick those things up as you go along, or ask someone if there's a sticking point, or pick up any of a million C textbooks. You might feel like you're missing out, sometimes, but on the other hand you will also be missing out on a lot of baggage that C programmers bring along that doesn't really fit the Obj-C way of thinking.

Trying to fight your way through the bare bones of the language AND a massive IDE (XCode) AND Project Builder AND all the frameworks you need for nifty GUI stuff is too much simultaneously, and also robs you of some intuition. So, make sure you can write, compile, and execute some bare bones programs right at the command line before you plunge into the Cocoa half of it. It greatly demystifies the whole process and it'll do a lot to help you diagnose where errors are coming from when you're immersed in a big Cocoa project.

Objective-C is really a beautiful, small, and simple language that you really can learn thoroughly in a short time, unlike some other popular object oriented languages named after letters of the alphabet. Kochan's book is good, and the comp.lang.objective-c group is a pretty friendly, helpful place.
posted by Wolfdog at 4:45 PM on September 22, 2005 [1 favorite]

I found 'Cocoa Programming for Mac OS X' by Aaron Hillegass a great introduction to Cocoa and Objective-C. It assumes you know a bit of C syntax, but to be honest it's nothing that you can't figure out from context.
posted by chrismear at 4:48 PM on September 22, 2005

The CocoaDev wiki is a great resource for OS X programming. It includes links to introductory Cocoa and ObjC resources (e.g. CocoaIntroduction).

You don't necessarily have to use Objective-C for Cocoa programming. Many languages have Objective-C bridges so that one can use Cocoa to write applications in one's favourite language. I know that at least Python's and OpenMCL's Cocoa bridges work fairly well.
posted by bpt at 4:56 PM on September 22, 2005

I certainly second Hillegass for the Cocoa part of things. I'm not sure what bpt was trying to link to with the 'Objective-C bridges', but if you're coming at this with a blank slate, Objective-C is the way to go. If you already had some language you were in love with then it might be worth figuring out how to use it with Cocoa.
posted by Wolfdog at 5:04 PM on September 22, 2005

I'd very strongly suggest using Python or C++ instead of Obj-C. My personal bias (C/C++ coder) is that Obj-C is an unelegant steaming pile of hacks that only was included in OSX because of NeXT. My main complaint is that ObjC tries to merge two languages instead of extending C, like C++ does. If you don't like C syntax, why use C at all?
posted by devilsbrigade at 5:12 PM on September 22, 2005

You really need to be a strong C programmer before learning Objective-C. All the C principles that you would use as a C programmer are present in Objective-C and you will use them on a daily basis.

I would definitely start with a good lightweight C text book and get to know the language. It will also give you a good foundation that will help you with other languages. Avoid Objective-C, or for that matter anything outside of the standard C libraries until you gain confidence with the language.
posted by schwa at 5:14 PM on September 22, 2005

devilsbrigade: "unelegant steaming pile of hacks that only was included in OSX because of NeXT"

And yet look at all the cool new applications written in Cocoa that we're getting on Mac OS X? And look how crappy a lot of the old Carbon C/C++ feel when compared side by side?

Cocoa isn't just about the Objective-C language. It is also a very rich and powerful framework that gets so many things right and without any of the cruft that C++ requires. Programming in Cocoa is a joy. I used to be a fulltime hardcore C++ developer and ever since switching to Objective-C I'm finding I am at least twice as productive. Coding with Objective-C is a pleasure, with C++ it rapidly becamee a chore.
posted by schwa at 5:21 PM on September 22, 2005 [1 favorite]

If you'd like to get your feet wet in C, I've found this tuturial handy.
posted by wheat at 5:21 PM on September 22, 2005

C is a royal pain in the ass for newbies, and objective C just adds another layer to understand. Python, by contrast is very pleasant to learn and use. With the pyObjC bridge and py2app your app will be just as 'native' as any other.

*But* since pyObjC just translates python to objective C, you will have to refer to Apple's documentation for the details of each method. Apple's docs reference Objective-C, so you will have to be constantly doing mental translation, which means you'll have to teach yourself a bit of Objective-C anyway. This might be a good way to get started though.

Another option is to use the wxPython gui library. The downside that this calls the carbon api, so you won't be able to take advantage of some of Cocoa's niceties. The upside is your app will be completely cross platform.
posted by Popular Ethics at 5:34 PM on September 22, 2005

That's fantastic. "Don't learn objective C, it's an extra layer. Instead, learn Python. And learn a system for turning python into Objective C. And, incidentally, you'll have to learn Objective C while you're at it."

mboszko, good luck, and enjoy what is likely to be a doozy of a thread here.
posted by Wolfdog at 5:43 PM on September 22, 2005 [1 favorite]

Best answer: As someone currently struggling through Cocoa via PyObjC, and who is by no means a programming neophyte, I have to say it's probably easier to go the "direct" route and learn Objective-C and Cocoa together, via the books mentioned above (specifically Hillegass', as it gets tons of love everywhere I look).

That said, once you feel somewhat comfortable reading Objective-C syntax and how to do things with it and Cocoa, Python is an excellent language and is probably going to be more useful overall than if you're not burned out by the time you find yourself making simplish-to-mildly-complicated apps with ObjC, I'd definitely suggest picking up Python and then using the PyObjC bridge.
posted by cyrusdogstar at 6:08 PM on September 22, 2005

Wolfdog: That's fantastic. "Don't learn objective C, it's an extra layer. Instead, learn Python. And learn a system for turning python into Objective C. And, incidentally, you'll have to learn Objective C while you're at it."

Oh hey, I fully realize the incongruity, that's why I pointed it out. I'm just suggesting some other avenues.
posted by Popular Ethics at 6:16 PM on September 22, 2005

The worst part about programming is the programming. It's immensely simple to read lots of books and copy and paste some code from a tutorial, but actually sitting down and writing something is what tends to ruin an otherwise good learning experience.

My advice is this: Just code. It's the only way to learn. Personally, I'm a horrible procrastinator. I've asked the same question you asked in this thread a million times, and in all honestly, there is no good answer. Learn some C (or really any other programming language. Once you know one it is very simple to move around) and sit around coding some stuff in the simplest way possible.

Once you're comfortable with sitting down and coding (and the inevitable forays deep into documentation territory) then try checking out some Obj-C tutorials. It's not any easier "just learning" Objective C any more than it is to "just learn" to ride a motorcycle if you've never ridden a pedal bike.

You need balance, and the best way to get that is to just write code.
posted by zerolives at 6:23 PM on September 22, 2005

Screw C/C++/ObjC. Go with Python. You will not regret it.
posted by five fresh fish at 7:57 PM on September 22, 2005

Another note: XCode is very easy to use and free, but its optimised for use with Objective-C. (for Python I use TextWrangler)

To answer your actual question though, I'm trying to find a book like the one I used to teach myself C++. It was especially useful, because it had chapters for C, C++ then Java, and described how each built upon its predecessor. I'll keep looking.
posted by Popular Ethics at 8:14 PM on September 22, 2005

The book that Wolfdog linked to gets some rave reviews here, including this:
"At last! At Last! A book on programming Objective C that doesn't require you to know C first!"

I think zerolives has a point, but personally I like to have a tutorial when I'm starting out. Just make sure to stop at the end of each chapter and try to implement what you've learned, rather than just trying to commit it all to memory.
posted by Popular Ethics at 8:35 PM on September 22, 2005

And yet look at all the cool new applications written in Cocoa that we're getting on Mac OS X? And look how crappy a lot of the old Carbon C/C++ feel when compared side by side?

That's not because Cocoa magically makes apps that look soooooo much better. It's because there are a lot of legacy UI resources in Carbon apps, since many of them are longtime Mac OS X applications. You could write a new Carbon app that's just as snazzy as any Cocoa app.

Still, Cocoa is going to be easier to learn than all the legacy cruft in Carbon, and Carbon will eventually go away, so yeah, learn Cocoa, Objective-C and all.
posted by kindall at 10:31 PM on September 22, 2005

Response by poster: Wow, what a slew of answers, and so many conflicting ones! ;-)

At the moment, I have a goal in mind that involves wanting to use Objective-C with Cocoa. Using Python or some other language with a bridge to ObjC seems like learning Chinese and hiring a translator, when what I really want to do is to just speak Russian. Thanks for the plugs, though. Maybe once I'm comfortable with ObjC, I'll have the time and inclination to branch out to other languages. For now, though, I think it would only slow the learning process.

Hillegass' book was one of those I've looked at (in addition to the O'Reilly "Learning Cocoa" book), but says it's designed for "programmers who already know some C programming and something about objects." Since my previous experience is with BASIC, neither of those qualifications applies. I consider myself a pretty fast learner, and quite possibly could eventually learn from context and inference, but I think I'll progress faster if I have a clear path in front of me. If the Kochan book really does introduce ObjC from the bottom up, and introduces concepts necessary for object-oriented programming, that seems like maybe the place I should start. Hillegass' Cocoa book does seem like the next logical step after I've familiarized myself with the language.

Thanks for all the answers so far, folks. Please feel free to post more comments, though. Especially those of you that feel I should get a good handle on C before moving to ObjC-- what is it exactly that you feel I'll be missing by not learning C first? Do you have any evidence of programmers who've skipped that step that you feel now code in inappropriate ways?
posted by mboszko at 10:55 PM on September 22, 2005

Well, bear in mind that you don't have to do all that wierd Python to ObjC stuff to do Python. OSX includes a normal python with every distribution, and it's a joy to learn Python. Also, Apple includes bindings to its CoreGraphics library, which is nice in and of itself, but also starts you toward coding Mac specific stuff. There's also some stuff to call AppleScript from Python, but honestly, I just use Python by itself.

What's your project that requires Objective-C? It's quite likely there are other ways to do it...
posted by freebird at 11:25 PM on September 22, 2005

Best answer: what is it exactly that you feel I'll be missing by not learning C first?
Objective-C has replacements for most of the deficiencies of C, so you probably won't suffer too much, except those books will expect you to know the syntax (which isn't difficult to pick up anyway)

However, since ObjC is a superset of C, those warts will often show up (usually in code from old C gurus). I'm thinking things like memory management, pointers, casting, and (horror) C strings.
posted by Popular Ethics at 7:01 AM on September 23, 2005

And I hope by plugging Python we don't sound too evangelical. Objective-C is a perfectly fine language, is well supported by Apple's tools, and is waaaay nicer than C++.
posted by Popular Ethics at 7:03 AM on September 23, 2005

You need to know your way around C to do anything with Objective-C. Basic datatypes, pointers, arithmetic, function calls, etc. You don't need to know C memory allocation, but that's about it. Debugging is much much easier when you know that objects are structs in memory, object references are pointers, and object messages are just fancy function calls. I found a lot of Objective-C impossible to understand until I realised what was happening underneath.

(And at one time or another, you'll be forced to use a Carbon API to do something, and knowing C here is required)
posted by cillit bang at 10:35 AM on September 23, 2005

Response by poster: Well, right, but the Kochan book (I picked it up today) does include information about basic datatypes, arethmetic, function calls, as they apply to both C and ObjC-- and there's even a chapter (#13) on "Underlying C Language Features," dealing with arrays, functions, structures, pointers, unions, etc.

In fact, the opening sentences are, "This chapter describes features of the Objective-C language that you don't necessarily need to know to write Objective-C programs. In fact, most of these come from the underlying C programming language." It then goes on to recommend you skim over it to get an overview of the material, but then warns that because C is a procedural language, some of that chapter's features go against the grain of object-oriented programming.

It seems to me that with this book, I'll be learning what I need to know to use ObjC thoroughly, without all that tedious mucking about learning language features I'll rarely (if ever) need, and a procedural programming style I'll have to unlearn when I move on to ObjC. It seems if I can learn ObjC and start using it well, when I get to the point I need to use a C and a Carbon API to do something, I'll be more comfortable with "just figuring it out." Getting into it, though, I'd much rather learn OOP the right way 'round the first time.

I did take a closer look at Python & Cocoa, and it looks intriguing. I still think I'm going to stick with ObjC for now, but I'll definitely keep that in mind for future research. It just seems to me that knowing ObjC will serve me better in understanding the Foundation and AppKit frameworks, and getting up to speed with Cocoa.

How many of you learned ObjC as your first 'real' language? I'm just curious to know, as I have a suspicion that the folks who are recommending I learn C first are speaking from their experience of learning C first, and are maybe not being as objective as they could. ;-)
posted by mboszko at 11:40 AM on September 23, 2005

« Older Should we go to Prague or Amsterdam for New Year's...   |   Cub Scouts - yes or no? Newer »
This thread is closed to new comments.