Make App Pie

Training for Developers and Artists

Bass ackwards with Objective C.

It drives me nuts, thinking backwards.

in Java or C++ or C, functions and methods are simple. They’re close to what I did in Pascal a quarter century ago:

public int sampleMethod(int y){
//statements go here
return y;
}

and then the call would be

a=sampleMethod(5);

No biggie. If sampleMethod was in a an object I was calling,

a= theObject.samplemethod(5);

But Objective C turned things around. Definitions are simple enough for single parameters:

- (int) SampleMethod:(int) y {
//statements go here
}

but the sending a message looks so different:

a=[theObject samplemethod: 5];

I get confused.  when you have something with multiple parameters in it like

-(void) fillCircleAtPoint:(CGPoint)p withRadius:(CGFloat)radius inContext:(CGContextRef) context{ //stuff here

}

and sending a message to

[self   fillCircleAtPoint:p withRadius:radius*0.5 inContext:context];

it just seems wrong. The withRadius: and inContext: just seem wrong.

They aren’t of course, and it does add to readability.

I get stuck with remembering which object I’m sending a message to, and those funky multiple parameter methods with the extra bits.

I’m silly I’m sure, but it is a paradigm change for me, And I’m guessing someone who will eventually read this.

See you are not the only silly person out there.

One response to “Bass ackwards with Objective C.”

  1. […] I started Making App Pie, one of my big frustrations was wrapping my head around defining methods. I was used to C++ and Java functions. Objective-C and its Smalltalk roots just threw me. Now going […]

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: