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: Graham Cox <email@hidden>
- Date: Fri, 11 Jul 2008 00:38:39 +1000
Bear in mind that the names you choose for these parameter variables
are unimportant really, they don't affect the public interface of your
class and don't even have to match the header.
What I would suggest though is that you adopt a naming convention for
your instance variables (ivars) that consistently flag them as such.
Some people use a leading underscore, but Apple say not to do that. I
personally use 'm' (for 'member') which is a carry-over from my C++
days, but anything consistent is good. This not only fixes your
shadowing problem, but makes code far more readable by indicating at a
glance where a given variable lives.
Graham
On 11 Jul 2008, at 12:25 am, an0 wrote:
I've been always stumbling on the embarrassment of "warning: local
declaration of 'xxx' hides instance variable" for my init methods,
because I really can't figure out a nice naming pattern for parameters
used to assign to instance properties, and I am always apt to write
code like this:
- (id)initWithURL:(NSString *)url title:(NSString *)title
tags:(NSString *)tags note:(NSString *)note time:(NSString *)time
count:(NSUInteger)count
since it is most natural(to me). Then I just see XCode spew out lots
of annoying warnings like these:
Line Location Post.m:28: warning: local declaration of 'url' hides
instance variable
Line Location Post.m:28: warning: local declaration of 'url' hides
instance variable
Line Location Post.m:29: warning: local declaration of 'title' hides
instance variable
Line Location Post.m:29: warning: local declaration of 'title' hides
instance variable
Line Location Post.m:32: warning: local declaration of 'time' hides
instance variable
Line Location Post.m:32: warning: local declaration of 'time' hides
instance variable
Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
Even though I then follow the general naming rules to prepend an
indefinite article to each singular noun, I still have those plural
nouns sitting there, which now looks this:
- (id)initWithURL:(NSString *)aUrl title:(NSString *)aTitle
tags:(NSString *)tags note:(NSString *)aNote time:(NSString *)aTime
count:(NSUInteger)aCount
Set aside the oddness of aTime and aCount, my XCode still complain:
Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
Line Location Post.m:30: warning: local declaration of 'tags' hides
instance variable
Am I supposed to use something like aGroupOfTags instead of just tags?
_______________________________________________
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
_______________________________________________
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