On Aug 30, 2008, at 10:31 PM, Jon Davis wrote:
So do no-ops exist solely for the sake of being there for convention, i.e. "do this if you're implemented, ignore if not"?

I'd adjust two things about your wording.

First, a no-op method *is* implemented. It has an implementation that happens to do nothing. This is a perfectly valid method implementation:

    - (void)myBoringMethod
    {
        // Does nothing.
    }

Second, I wouldn't say no-ops are there by convention. Rather, they're part of the explicit design of how the program is supposed to behave. If a method does nothing, why was it created at all? The typical answer is either (a) it's a fallback behavior under certain conditions (so it's only a no-op under those conditions), or (b) it's a default behavior which can optionally be overridden by a subclass.

The case you saw, -[NSAutoreleasePool release], is an example of (a). If you're using retain/release for memory management, the method does something; it's not a no-op. If you recompile your code to use GC, - release becomes a no-op. You can keep calling it in your code -- you don't have to go remove all your calls to it -- but it will simply do nothing.

As an example of case (b), there is a class called NSColorPicker with a method called -attachColorList: that does nothing. The method will get called and it will do nothing for a regular instance of NSColorPicker. You can create a custom subclass of NSColorPicker whose -attachColorList: method does something.

To see more examples of this second kind of no-op, you can Google for this (enter the stuff inside the square brackets): ["does nothing" override site:developer.apple.com].

Hope this helps,
--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 [EMAIL PROTECTED]

Reply via email to