Re: Underscore in method names
Re: Underscore in method names
- Subject: Re: Underscore in method names
- From: Graeme Hiebert <email@hidden>
- Date: Wed, 27 Feb 2002 07:53:31 -0800
On Tuesday, February 26, 2002, at 02:33 PM, Kurt Revis wrote:
Yes, I know--it's my least favorite wart in practical Objective-C
usage. The alternatives for naming methods (in this case, private
methods internal to a class's implementation, not to be used
externally) seem to be:
1) Underscore before the method name (_myMethod). Obviously this runs
the risk of colliding with a method that already exists, when I am
subclassing someone else's object. I can check against this in the
current development environment (by running class-dump on the
superclass and all of its superclasses), but there's still the
possibility that it will break in the future.
2) Just use plain names (myMethod). This is a little safer--I still
have to check all the public methods on all superclasses but I can just
do that through the header files. However, I still have to do the
class-dump to be perfectly safe, because there are some private methods
which Apple doesn't prefix with an underscore (at least, there
historically have been). And it still could break in the future. (And
this makes it impossible to distinguish between private and public
methods, which is a really useful thing to be able to do at a glance.)
3) Prefix all methods with a hopefully-unique identifier (BLAH_myMethod
or something). Very safe, very ugly.
4) Put an underscore at the *end* of the method name: myMethod_ . We do
this for data members in C++ classes at work, and it only seems natural
to do the same for private methods.
-g
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.