• 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: Objective-C Instance Variable Names
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Objective-C Instance Variable Names


  • Subject: Re: Objective-C Instance Variable Names
  • From: Quincey Morris <email@hidden>
  • Date: Sat, 5 Apr 2008 18:17:58 -0700


On Apr 5, 2008, at 15:44, Dennis C. De Mars wrote:

There's another solution besides naming conventions. I've been through most of them -- underscore prefix or postfix, prefix with "m" etc. I generally don't find naming conventions very satisfactory. It seems like I'm trying to encode something into the name that should be evident from the syntax of the language or the context the variable is used in.

I think the issue with all the solutions suggested so far (myWhatever, theWhatever, aWhatever, mWhatever, lpWhatever, _whatever, self- >whatever) is that they're trying to encode primarily *syntactic* information into the variable name. While there's nothing wrong with that, some of us (including you, it seems from your comments) find it somehow ugly or redundant or ... something.


Another approach is to qualify the property name *semantically* instead. The most common situation where I run into local/instance variable name conflicts is setter methods. If the property and the instance variable are both 'whatever', it makes sense to me to call the setter argument variable 'newWhatever', because that is in fact what it is. That makes it natural, when you need to move the instance variable into a local variable, as often happens when releasing and retaining, to call it 'oldWhatever'.

In other scenarios, other choices suggest themselves. Sometimes it makes sense to call a local copy of the instance variable 'currentWhatever'. For arguments to initializers, where a value is passed in that's going straight into an instance variable, the argument can be called 'initialWhatever'.

Notice that none of those names tell you what the variable is, syntactically, but they do tell you what it's for, semantically. To me, that's useful information.

FWIW.


_______________________________________________

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: Objective-C Instance Variable Names
      • From: Richard Somers <email@hidden>
References: 
 >Re: Objective-C Instance Variable Names (From: Mario Gajardo Tassara <email@hidden>)
 >Re: Objective-C Instance Variable Names (From: "Dennis C. De Mars" <email@hidden>)

  • Prev by Date: [MEET] April CocoaHeads Mac Developer Meetings CORRECTION
  • Next by Date: Re: NSTreeController / CoreData still broken in 10.5?
  • Previous by thread: Re: Objective-C Instance Variable Names
  • Next by thread: Re: Objective-C Instance Variable Names
  • Index(es):
    • Date
    • Thread