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: Alex Zavatone <email@hidden>
- Date: Tue, 26 Jan 2016 15:43:59 -0500
On Jan 26, 2016, at 2:10 PM, Jens Alfke wrote:
>
>> 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.
>
That's the exact first convention that I am aware of which I am referring to.
> (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.
Additionally, when creating an @property, the compiler does this automatically, when it create the iVar, correct?
> 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
So, as now as options, we also have:
s to prefix for a static
k for a constant or #define
my to prefix locals
With @public and @protected and @private sadly starting with the letter p this leaves us without obvious options to connote the style of the variable.
I'm going to step out on a limb and since Xcode has supported editing in UTF-8 and 16, that we look into those character sets and pick some symbols that accurately represent public, protected and private.
These symbols should mean what they represent, and be visually distinct.
They could be put in a little template for copying and pasting when we use them.
The goal here is that when we eyeball our code, we want as much information to be presented to us as possible about the nature of each element that we are looking at, it's got to be easy to use and visually make sense.
Any ideas for valid characters to prefix @public and @protected and @private with?
Here are a few I just pulled up that should display well enough in Menlo Regular, but might not make it through email.
📢 public (megaphone - search the character panel for public)
⊖ ⊗ ⊘ ⊙ ⊞ ⨳ ☒ ⨷ ✖︎ private
℗ 🔒 ✔︎ protected (second item is the lock character, +1F512)
Reference
http://www.g8production.com/post/69593399838/private-protected-and-public-vars-in-objective-c
UTF-8 Character set
http://www.fileformat.info/info/charset/UTF-8/list.htm
_______________________________________________
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