• 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: A Data Object in Cocoa
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: A Data Object in Cocoa


  • Subject: Re: A Data Object in Cocoa
  • From: "email@hidden" <email@hidden>
  • Date: Sat, 10 Jan 2009 19:40:40 +0000


On 10 Jan 2009, at 19:23, Michael Ash wrote:

On Sat, Jan 10, 2009 at 12:39 PM, email@hidden
<email@hidden> wrote:

On 10 Jan 2009, at 17:18, Michael Ash wrote:

On Sat, Jan 10, 2009 at 12:08 PM, Alastair Houghton
<email@hidden> wrote:

On 10 Jan 2009, at 16:48, Michael Ash wrote:

As for underscore being reserved, I have never been able to figure out
any consequence of a conflict with an Apple ivar name. It may cause
your source to fail to compile, but it won't cause any *binary*
compatibility problems, which is the real menace.

I *think* the problem here is introspection... if you subclass an Apple
provided class and add an instance variable with the same name as one of
theirs, it's possible that any of the dynamic mechanisms the frameworks
(or,
for that matter, your own code) use to get the value of an object
property
might use the wrong variable, with unexpected results.

Not using an underscore won't save you here. Mechanisms like KVC will
look for ivars both with and without the underscore. In fact, leaving
off the underscore makes things worse: with the underscore, the
compiler will at least error when you try to recompile later on,
whereas without it the conflict will exist silently.


A cow-orker just pointed out to me that Apple does not, in fact,
recommend against an underscore prefix for instance variables. They do
recommend against them for private methods, but that's a completely
different question. It seems that the well-known recommendation
against _ivars is actually a misconception! If I'm wrong and just
missed it, I'd like to know where it says so. But no trace of such a
recommendation in Coding Guidelines for Cocoa: Naming Instance
Variables and Data Types:



http://developer.apple.com/DOCUMENTATION/Cocoa/Conceptual/CodingGuidelines/Articles/NamingIvarsAndTypes.html#/ /apple_ref/doc/uid/20001284



For what it's worth Anguish et al states (p99) that Apple reserves the right
to change "private" instance variables that begin with an underscore and no
prefix.
Anguish et al recommend and _ + unique prefix for ivars.

I don't have whichever book you're referring to so I can't see what it actually says, but your summary makes no sense. Apple can't change *your* ivars. If it means they reserve the right to change their own private instance variables that begin with an underscore and no prefix, well of course, that's what "private" means. That's why you should never directly twiddle another class's ivars. But that has nothing to do with how you should name your own ivars.

I agree that it is confusing, or meaningless, but I thought it might have contributed to the _ misconception.
A Google for - anguish "underscores and usage" - will show the passage I referred to.


Mike
_______________________________________________

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

Jonathan Mitchell

Central Conscious Unit
http://www.mugginsoft.com




_______________________________________________

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: A Data Object in Cocoa
      • From: "Michael Ash" <email@hidden>
References: 
 >A Data Object in Cocoa (From: nik heger <email@hidden>)
 >Re: A Data Object in Cocoa (From: Ken Thomases <email@hidden>)
 >Re: A Data Object in Cocoa (From: "Adam Foltzer" <email@hidden>)
 >Re: A Data Object in Cocoa (From: Alastair Houghton <email@hidden>)
 >Re: A Data Object in Cocoa (From: "Michael Ash" <email@hidden>)
 >Re: A Data Object in Cocoa (From: Alastair Houghton <email@hidden>)
 >Re: A Data Object in Cocoa (From: "Michael Ash" <email@hidden>)
 >Re: A Data Object in Cocoa (From: "email@hidden" <email@hidden>)
 >Re: A Data Object in Cocoa (From: "Michael Ash" <email@hidden>)

  • Prev by Date: Re: performSelectorOnMainThread
  • Next by Date: Re: A Data Object in Cocoa
  • Previous by thread: Re: A Data Object in Cocoa
  • Next by thread: Re: A Data Object in Cocoa
  • Index(es):
    • Date
    • Thread