Re: enough of accessors - how about private method naming conventions in the real world?
Re: enough of accessors - how about private method naming conventions in the real world?
- Subject: Re: enough of accessors - how about private method naming conventions in the real world?
- From: Bill Cheeseman <email@hidden>
- Date: Wed, 07 Aug 2002 05:36:07 -0400
on 02-08-07 2:28 AM, Nicholas Riley at email@hidden wrote:
>
On Tue, Aug 06, 2002 at 10:48:45PM -0700, Michael B. Johnson wrote:
>
> So we all know that Apple has coopted the "prefix your private methods
>
> with an underscore" idiom, and told us not to use it. Annoyingly
>
> enough, this is fair, since we don't have source to the Apple
>
> frameworks, and since any private methods one might implement using the
>
> same naming convention would silently override their particular
>
> implementation, leading to all sorts of nasty, hard to find bugs.
>
>
Actually, I didn't know this, where is it documented?
It is in fact mentioned in some official document somewhere, but I've lost
the reference. I'm too lazy to look for it, but here is a good enough
reference:
A message to this list from Apple's Mike Ferris on Nov 11, 2000:
"Prefixing methods with "_" to indicate private methods is reserved for
Apple's use. Same goes for exported functions (for static functions, go
nuts).
"If everyone uses this "_" convention it is bad because subclasses can
override an existing private method with one of their own without knowing
it. This could obviously wind up having really nasty consequences.
"In my own non-Apple code, I try to make private methods start with
"<Prefix>_" where <Prefix> is the prefix I am using for that project like
"TE" for TextExtras. Yes, it is ugly to have methods like
TE_myPrivateMethod:, but it is only ugly internally since they are private
methods.
"Now, for ivars, this is less of an issue since I am pretty sure the
compiler will complain if you wind up duplicating an ivar name from one of
your ancestor classes."
--
Bill Cheeseman - email@hidden
Quechee Software, Quechee, Vermont, USA
http://www.quecheesoftware.com
The AppleScript Sourcebook -
http://www.AppleScriptSourcebook.com
Vermont Recipes -
http://www.stepwise.com/Articles/VermontRecipes
Croquet Club of Vermont -
http://members.valley.net/croquetvermont
_______________________________________________
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.