On Dec 20, 2009, at 1:05 PM, Jeffrey Oleander wrote:

>> On Sun, 2009/12/20, Graham Cox <graham....@bigpond.com> wrote:
>> 
[...]
>> 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.
> 
> OTOH
> 
> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/ActionMessages/Concepts/TargetsAndActions.html
> 
> http://developer.apple.com/mac/library/documentation/Cocoa/Conceptual/SearchFields/Articles/ConfiguringTargetAction.html
[...other links to documentation snipped...]

Yes, SELs are used all over the place in Cocoa, but none of the linked examples 
shows a method using the name of the method that called it.  Rather, they show 
a method being given the SEL of a message to *send*.

I agree it probably makes more sense to use an enum to indicate intent.  
Another possibility is to factor things so that there are multiple methods for 
multiple intents, so instead of methods A1, A2, A3, etc. passing their own 
method names to method B, they instead call methods B1, B2, B3, etc., which 
might in turn call a private method _B that performs common logic.

--Andy

_______________________________________________

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