On 16/10/2009, at 11:54 AM, Frederick C. Lee wrote:

Both seem to work the same.
Is there any benefit of (1) over (2) or is it merely style of programming?

(1) isn't really an alternative way of implementing a method, it's just that the trailing semicolon is ignored. I'm not even sure if it's deliberately allowed (it wouldn't be for a C function) or merely an artifact of the way Obj-C is parsed.

-(void) foo
{

}

and

- (void) foo {

}

are both perfectly valid ways of defining any block in C and always have been (though I personally abhor the second style yet seem to be ploughing my own furrow on that one - almost everyone uses it :(

The ignored trailing semicolon is sort of useful when fleshing out the body of a class that you've declared methods for in the header - you need the semicolon for the method's prototypes, so you can cut and paste the prototype into the main body and just add a trailing block to implement the method - the semicolon doesn't have to be removed. However, again a personal thing, I prefer it not to be there so it's consistent with ordinary C functions, and provided you are just fleshing out the body from the headers for the first time (i.e. no other code has yet been written) doing a search/replace of ';' for '\n {\n\n\n}\n\n' is a useful way to convert all your header methods into bodies ready to be filled in with code.

--Graham


_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to