Re: Obj-C - your thoughts on hiding data members?
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