In Objective-C, method names have arguments thrown in the middle of them. I would say that for - (void)setTo:(int)n over:(int)d
, a good analogous C function would be void function setTo_over_(int n, int d)
.
I've added underscores and the word "over" because the placement of the arguments and the word "over" are parts of the method name. The method's name is really setTo:over:
. "setTo" is only the first half of the method name.
This is really useful when you're doing something like, for example, colorWithRed:1.0 green:0.5 blue:0.7
. In C, this would be colorWithRed_green_blue_(1.0, 0.5, 0.7)
, and it's a little hard to tell which number is which. Thanks to Objective-C's ability to put arguments right in the middle of the method name, we can clearly see which number is which component of the color.
(Worse yet, because underscores look funny, and just because of convention, it's likely that a C function would be more like color(1.0, 0.5, 0.7)
, and now we're just completely confused. That is, what we usually use Objective-C's arguments-in-the-middle-of-a-method feature for is for fake "named arguments".)
You should check out Cocoa Style for Objective-C, Part I. It has a detailed explanation of good style when naming methods, and a bit of comparison between Objective-C methods and C functions.