views:

524

answers:

4

Here's a quicky question. Which method name makes the most sense for an Objective-C Cocoa application?

-(void) doSomethingWithAnimation:(BOOL)animated

or:

-(void) doSomething:(BOOL)animated

or even:

-(void) doSomethingAnimated:(BOOL)animated
+3  A: 

-(void)doSomethingAnimated:(BOOL)animated seems most consistent with Apple's naming style. For reference, check the iPhone UIKit docs - UINavigationController's -popToRootViewControllerAnimated: method, for instance.

Noah Witherspoon
+6  A: 

I think the Cocoa convention would give your examples the following semmantics (ignoring the BOOL type for the argument, obviously):

-(void) doSomethingWithAnimation:(BOOL)animated

would actually expect an Animation as the parameter (i.e. something that represents the animation.

-(void) doSomething:(BOOL)animated

would expect the Something to do.

-(void) doSomethingAnimated:(BOOL)animated

would, as Noah answered, do something with optional animation.

Barry Wark
A: 

Here's another option to consider: make two methods, -doSomething and -doSomethingWithAnimation.

Then, if you want, you can have them both tail-call a third, private method, and give that method any name you want. :)

Peter Hosey
This won't work so well if the animated parm is coming from elsewhere consider this:- (void)doSomethingAnimated:(BOOL)anmimated { [self doSomethingElse:animated]; [otherView doAThirdThing:animated];}becomes a PITA if you have 2 different methods.
Mike Akers
A: 

write your comment clearly and tersely for example : //do Something with the Animation

Then write your method name based on this comment, like below doSomethingwithAnimation:(BOOL)animated

Objective-C and Cocoa are designed to read well, so if your method cannot be a clear narrative of your code, it might not be well named.

Iggy