Re: Any good advice for naming parameters of init methods?
Re: Any good advice for naming parameters of init methods?
- Subject: Re: Any good advice for naming parameters of init methods?
- From: Ricky Sharp <email@hidden>
- Date: Thu, 10 Jul 2008 14:03:03 -0500
On Jul 10, 2008, at 11:19 AM, glenn andreas wrote:
The problem is that while when you recompile you'll see the
conflict, for existing users (who won't be compiling from source),
if they use KVC they'll have the problem.
@interface NSFoo {
id _reserved;
}
@end
@interface MyFoo: NSFoo {
float _value;
}
@end
And OS X+1 comes out with:
@interface NSFoo {
int _value;
}
@end
Any of your code that used _value (like, say, for bindings) could
suddenly break for users of OS X N+ 1 (since they won't be compiling
from source to see what is going on).
Granted, it's rare that this happens, but from time to time reserved
fields do get converted to something used. And lets face it, if you
hear "it works fine on OS X N, but breaks on OS X N+1", "ivar
collision" isn't the first thing you'll think about to try to track
down the problem...
Worse, this could actually happen on an OS X N+ 0.1 release and the
headers wouldn't get updated so you won't even have the safety net
of seeing compiler errors. Similarly, if you target the OS X N SDK,
you won't see the new headers either.
"Haven't run into such problems" != "Such problems don't happen"
I definitely got burned by this myself a few years back (when the
NSAnimation API was added). I didn't use that class at all, but got
very strange runtime issues with an NSCell subclass of mine. One of
the cell's ivars name collided with NSAnimation. And, in code like
this:
[[self cell] foo];
Since, [self cell] returns id, it ended up thinking that the return
object was actually an NSAnimation instance and not my cell.
From that point onwards, I've renamed all my classes, ivars, binding
names, keys, etc. to use a custom prefix/suffix of II (company name).
Details of this approach can be found in the archives.
___________________________________________________________
Ricky A. Sharp mailto:email@hidden
Instant Interactive(tm) http://www.instantinteractive.com
_______________________________________________
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