Linked by Jared White on Thu 24th Apr 2003 17:49 UTC
General Development There are two major varieties of Cocoa available. The first variety, possibly the more well known of the two, is the kind that you can use to make a nice warm cup of chocolate milk. While tasty, it's hardly proper subject matter for an operating systems information site. The second variety is far more on-topic: a programming environment for Apple Mac OS X that is the modern evolution of of the original NeXTSTEP frameworks. That's what I'm here to talk about today.
Permalink for comment
To read all comments associated with this story, please click here.
Objective-C behavior
by Doc O'Leary on Thu 24th Apr 2003 21:15 UTC

Messages to nil (or the Nil class) normally return nil (some runtimes allow this behavior to be easily modifed. This allows you set up a big chain of messages and only worry if the final result is nil:

foo = [[[[NSData alloc] initWithContentsOfFile: @"my.data"] autorelease] md5];

You don't have to deal with types in ObjC the same way you're think of. Every object *does* have a type/class it belongs to, but you need not worry yourself over the particulars to perform an operation. If you have a collection that responds to -addObject:, that is enough; why sweat over it being an array, set, linked list, whatever?

In some runtimes it *is* possible to create objects on the stack. That is not part of common systems, so clearly there is little benefit to it in the real world.

As far as syntax issues go, some of you people simply need more exposure. A professional programmer should be able to get beyond syntax issues relatively easily, and ObjC has the most minor of syntax differences from C. For your example, the equivalent Cocoa code would be:

[v addObject: [NSNumber numberWithInt: 1]];

Hardly a difficult read. Where the ObjC syntax really shines is with multiple arguments. Compare:

new Account("Steve", 50, 32, "Phil")

with

[Account accountWithOwner: @"Steve" age: 50 startingBalance: 32 accountManager: @"Phil"]

I'd much rather come across the later in code I had to maintain.