• 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: Name instance variables, methods and parameters.
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Name instance variables, methods and parameters.


  • Subject: Re: Name instance variables, methods and parameters.
  • From: Raphael Sebbe <email@hidden>
  • Date: Wed, 28 Jan 2004 15:56:37 +0100

Hi,

Prefixes other than _ won't work with automatic (no accessor) KVO/KVC. My personal way of defining ivars is:

- I use underscores for classes derived from NSObject (I mean directly, not from another NS... class)
- no prefixes for others

And I have to admit 2nd rule is sometimes forgotten. IMO, underscores provides better readability.

Perhaps we need a way to configure automatic accessors (KVO/KVC) ?

Raphael

On 28 Jan 2004, at 06:55, Daryn wrote:

Apple warns not to use underscores because they reserve them for use
within the frameworks. Refusing to obey this requirement will cause
trouble if/when one of your framework subclasses stomps over the
framework's private method or ivar.

For private ivars, just use @private in the interface and give them a
unique prefix like my_ if you don't want to collide with method args.
For private methods, just don't add them to the interface or use a
<MyObject>Private category, perhaps in the source file rather than the
header if you really don't want people to see them.

On Jan 27, 2004, at 9:00 PM, Czarny, Eric wrote:

I know that this may be an awfully common question, but I haven't
found a
single answer, nor a collection of answers, to give me a better idea.
The
section on coding style within Apple's developer documentation states
that
an underscore should not be used for naming private methods and
instance
variables. I know I have seen this topic being discussed at CocoaDev,
but
couldn't gather sufficient information. I'd like to continue to use an
underscore, but if it goes against Apple's own wishes, I'd like avoid
it if
I could.

The major problem I have is if I just use an unmodified instance
variable,
such as:

NSString *data;

instead of:

NSString *_data;

Which I like better, but conflicts with:

- (id)parseData: (NSData *)data;

I've seen people just use a single character as the name for the
parameter
name, but I feel it makes for less readable code.

I suppose it's all a matter of personal preference, but I'd like some
input
from more experienced developers.

Thanks!
Eric Czarny
_______________________________________________
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.

[demime 0.98b removed an attachment of type application/pkcs7-signature which had a name of smime.p7s]
_______________________________________________
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.
_______________________________________________
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.

References: 
 >Name instance variables, methods and parameters. (From: "Czarny, Eric" <email@hidden>)
 >Re: Name instance variables, methods and parameters. (From: Daryn <email@hidden>)

  • Prev by Date: Re: List of Images like in System Preferences
  • Next by Date: Re: Does each NSTableView requires its own controller?
  • Previous by thread: Re: Name instance variables, methods and parameters.
  • Next by thread: Re: Name instance variables, methods and parameters.
  • Index(es):
    • Date
    • Thread