• 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: "Dennis C. De Mars" <email@hidden>
  • Date: Sat, 5 Apr 2008 15:44:15 -0700

I didn't notice the Xcode syntax-coloring of the instance variables -- I'll have to try using that.

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.

So the solution I am toying with, which I think most people won't like because it is quite verbose, harkens back to the old days of programming on the Mac. If you ever used the MacApp application framework (in its original incarnation) you used Object Pascal, and in Object Pascal all instance variables had to be referenced as members of "SELF", so for instance you'd have to write something like "SELF.myVariable := 2;"

When the framework was converted to C++, one of the complaints that some MacApp programmers had was that the C++ syntax would be less clear in particular regarding instance variables, where you could write "myVariable = 2;" and it wasn't clear whether "myVariable" was an instance variable or not. The Object Pascal syntax always made it clear whether the variable was an instance variable without having to refer back to the object declaration.

It was pointed out to these people that you could just as easily use the equivalent "this->myVariable = 2;" I believe the MacApp code itself made heavy use of this convention. This mollified some Object Pascal fans.

I'm toying with doing this in my new project, just because I dislike coding properties like this into the name. I'm naming my instance variables anything I want to and then consistently referring to them with self->myVariable (to access the raw ivar) or self.myVariable if I want to use the accessor.

So far it seems to be OK, except that I don't particularly like the looks of it when used as the target of a message (as in "[self->target method];") although I don't have a rational reason for that opinion.

- Dennis D.
_______________________________________________

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: Quincey Morris <email@hidden>
References: 
 >Re: Objective-C Instance Variable Names (From: Mario Gajardo Tassara <email@hidden>)

  • Prev by Date: Custom Buttons - Tutorial/Examples...
  • Next by Date: Place NSView into NSView
  • Previous by thread: Re: Objective-C Instance Variable Names
  • Next by thread: Re: Objective-C Instance Variable Names
  • Index(es):
    • Date
    • Thread