• 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: Obj-C - your thoughts on hiding data members?
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Obj-C - your thoughts on hiding data members?


  • Subject: Re: Obj-C - your thoughts on hiding data members?
  • From: Jens Alfke <email@hidden>
  • Date: Tue, 26 Jan 2016 11:10:36 -0800

> On Jan 26, 2016, at 6:32 AM, Alex Zavatone <email@hidden> wrote:
>
> Since we're all computery and programmy and stuff, couldn't we put together a little matrix of the type of variable and come up with several loose standards?
> The reason I ask this (am pressing on this) is that a large amount of what communicates to the programmer is in the naming and casing convention of the words used.

There is a very longstanding convention in Objective-C — going back to the NeXT days — to prefix instance variables with underscores. You’ll see that in many of Apple’s headers (the ones that still list ivars in the @interface) and in some Apple sample code.

(There was a time when Apple was warning 3rd party developers not to do this because of name collisions with inherited ivar names, but that’s a non-issue with the modern Obj-C runtime.)

I would strongly urge that anyone prefixing ivars use this convention, for consistency. Additionally, I find that the underscore adds less visual clutter than a letter like “m”. Your brain doesn’t see it as a letter, so it doesn’t get in the way of reading the variable name.

Beyond that it’s a matter of preference. I prefix static variables with “s”, a convention that dates back to MacApp (~1988!). I don’t see any reason to prefix function parameters or locals in general, since they’re the default, although I sometimes use an “out” prefix for a by-reference parameter like an NSError**.

—Jens
_______________________________________________

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: Obj-C - your thoughts on hiding data members?
      • From: Dave <email@hidden>
    • Re: Obj-C - your thoughts on hiding data members?
      • From: Alex Zavatone <email@hidden>
References: 
 >Obj-C - your thoughts on hiding data members? (From: Graham Cox <email@hidden>)
 >Re: Obj-C - your thoughts on hiding data members? (From: Greg Parker <email@hidden>)
 >Re: Obj-C - your thoughts on hiding data members? (From: Alex Zavatone <email@hidden>)
 >Re: Obj-C - your thoughts on hiding data members? (From: Dave <email@hidden>)
 >Re: Obj-C - your thoughts on hiding data members? (From: Alex Zavatone <email@hidden>)

  • Prev by Date: Re: Dodgy Code - Low Level Memory Management Question!
  • Next by Date: Re: Dodgy Code - Low Level Memory Management Question!
  • Previous by thread: Re: Obj-C - your thoughts on hiding data members?
  • Next by thread: Re: Obj-C - your thoughts on hiding data members?
  • Index(es):
    • Date
    • Thread