Re: passing a method name?
Re: passing a method name?
- Subject: Re: passing a method name?
- From: Graham Cox <email@hidden>
- Date: Mon, 21 Dec 2009 00:29:00 +1100
On 21/12/2009, at 12:18 AM, Chunk 1978 wrote:
> i have a bunch of methods that will call one method. currently, i'm
> passing a string object so the called method will know which method
> had called it, and complete the proper task based on the method that
> called it.
Good programming practice encourages the idea that functions and methods are complete in and of themselves, and are invariant under different calling conditions. Variations should be accomplished using properly passed parameters, not information about where the function has been called from. I'd say this approach is going to bite you very, very hard if you persist with it. Nobody does this in professional programming, and where it is done inadvertently, it will usually be rejected and revised when code is peer-reviewed. So you might consider this comment part of a peer review.
The only situation this is considered acceptable is when passing a callback or completion method, where the called method calls the passed method but no part of its internal state depends on it.
> instead of creating strings and passing them, is it possible to pass
> the method name?
You can pass a SEL (selector) type but unless it's for the specific purpose of indicating a callback or completion method, I would strongly advise against it.
--Graham
_______________________________________________
Cocoa-dev mailing list (email@hidden)
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:
This email sent to email@hidden