Re: passing a method name?
Re: passing a method name?
- Subject: Re: passing a method name?
- From: Matt Neuburg <email@hidden>
- Date: Sun, 20 Dec 2009 10:17:48 -0800
- Thread-topic: passing a method name?
On Mon, 21 Dec 2009 00:29:00 +1100, Graham Cox <email@hidden>
said:
>
>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.
Not everyone would agree. I've written a professional application
("professional" meaning I was paid for it and it was used in an enterprise
situation) that depended on this, and it never bit me, hard or otherwise.
Certain aspects of the framework (for example, the way sheets work), and the
dynamism of Objective-C messaging (for example, you can construct the name
of the method to be called, in real time, based on the name of another
method, and then call it), sometimes make this a very sensible way to
implement a state machine. m.
--
matt neuburg, phd = email@hidden, <http://www.tidbits.com/matt/>
A fool + a tool + an autorelease pool = cool!
AppleScript: the Definitive Guide - Second Edition!
http://www.tidbits.com/matt/default.html#applescriptthings
_______________________________________________
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