• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Question about Style wrt "private" methods
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Question about Style wrt "private" methods


  • Subject: Re: Question about Style wrt "private" methods
  • From: Jens Alfke <email@hidden>
  • Date: Wed, 18 Nov 2009 10:49:27 -0800

On Nov 18, 2009, at 9:44 AM, Michael de Haan wrote:

> "Names of most private methods in the Cocoa frameworks have an underscore prefix (for example, _fooData ) to mark them as private. From this fact follow two recommendations.
>
> 	• Don’t use the underscore character as a prefix for your private methods. Apple reserves this convention."

This is unfortunately true. The danger is that if you add an _-prefixed method to your class, it might conflict with a private method declared in a superclass. If this happens your method will override the internal one, and Really Bad Things will probably happen. It's a rare problem but it has happened before. (And even if everything works well now, any future OS update might add a new private method in a superclass that breaks your code. Again, this has actually happened.)

Using a naming convention for your private/internal methods is a good idea; just use a different convention. I've seen people use an "i_" prefix, for example.

—Jens_______________________________________________

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

  • Follow-Ups:
    • Re: Question about Style wrt "private" methods
      • From: Jim Correia <email@hidden>
References: 
 >Question about Style wrt "private" methods (From: Michael de Haan <email@hidden>)

  • Prev by Date: Re: Help needed in Writing network usage monitor application
  • Next by Date: Re: Where are the interface builder components?
  • Previous by thread: Question about Style wrt "private" methods
  • Next by thread: Re: Question about Style wrt "private" methods
  • Index(es):
    • Date
    • Thread