Re: ivar name clashes with gcc3
Re: ivar name clashes with gcc3
- Subject: Re: ivar name clashes with gcc3
- From: Ricky Sharp <email@hidden>
- Date: Thu, 9 Feb 2006 16:29:33 -0600
On Feb 9, 2006, at 3:51 PM, Camillo Lugaresi wrote:
On 08/feb/06, at 23:14, Ricky Sharp wrote:
Finally, other reasons why I went "nuts" in renaming everything:
* Wanted to guarantee uniqueness of names used for custom
bindings. My controls often use inherited bindings, but I
sometimes need to provide my own implementation. Having _II
allows me uniqueness and also it's easy to see at-a-glance what
are my bindings vs. those provided (as seen in the bindings
inspector in IB).
* There's a very small chance that some of my code may be released
for the consumption of other developers. I wanted to ensure no
collisions would exist with their code.
What I've effectively done is guarantee all my code lives within
its own "namespace".
Interesting. This approach has obvious benefits, and I wonder why
Apple doesn't seem to encourage it at all (in sample code,
documentation etc.). Is there a list of best practices for dealing
with namespace problems in Objective-C? (apart from those two-
letter prefixes everybody puts on class names...)
No list that I know of. I agree though that Apple's samples may want
to point this out. Or, perhaps the main document on the Obj-C
language can mention best practices.
One of a few things I forgot to mention is that I also prefix all key
names used in keyed archiving; again to avoid any possible
collisions. If you have Accessorizer, you can do this easily by
setting a custom prefix in the "Keyed Archiving" settings pane.
If I wanted to summarize what I've done into a list...
* class names prefixed with II
* suffix all ivars with _II
* custom bindings also suffixed with _II
* suffix first part of method names with _II (e.g. currentValue_II,
doThis_II:andThat:)
* prefix typedefs (structs, enums, etc.) with II
* when making categories, add II to the filename (e.g.
NSImage_IIEffectsAdditions.h)
* category names are prefixed with II
* names of keys used in keyed archiving prefixed with II
Note that in some cases I chose to suffix rather than to prefix.
This was because I wanted to adhere to the Obj-C guidelines of having
method names, ivars, etc. start with a lower-case letter. Things
just looked too strange being prefixed with 'iI'. Accessors also got
a bit clunky because they could not be prefixed. So the II showed up
later anyhow (e.g. setiicurrentValue:) For some reason, I find
setCurrentValue_II: to read better :)
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden