On 10 Jul '08, at 8:52 AM, Sean McBride wrote:

On 7/11/08 12:38 AM, Graham Cox said:

What I would suggest though is that you adopt a naming convention for
your instance variables (ivars) that consistently flag them as such.
Some people use a leading underscore, but Apple say not to do that.

Do the docs still say that?  We've had this discussion before:
<http://www.cocoabuilder.com/archive/message/cocoa/2008/4/3/203159>

With any naming convention, the possible problem is a conflict with a name in a superclass. Apple's Cocoa frameworks tend to use a "_" prefix for both ivars and private method names.

Method-name conflicts are very bad and will cause trouble at runtime. The worst case is where Apple adds a method, in a new release of the OS, which has the same name as one of your methods. This will probably cause your app to break because when the framework calls that private method, it gets your implementation instead.

Ivar-name conflicts are, IIRC, a lot less harmful. For the most part, ivar names are used only at compile time (the generated code just accesses ivars by a byte offset from the object) so the effect in the above situation will be that your app continues to work fine, but when you try to recompile the app using the SDK for the new OS, you'll get a compile error about a duplicate ivar name. Then you just rename yours.

Someone did bring up the issue of dynamic ivar-name lookups. KVC sometimes uses these. It's possible there could be runtime problems in this case, although I'm not sure. All I can say is that I've been using the "_" prefix in my code for almost eight years now without running into such problems.

—Jens

Attachment: smime.p7s
Description: S/MIME cryptographic signature

_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

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:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to [EMAIL PROTECTED]

Reply via email to