Re: Suppressing variable hiding warning in Xcode
Re: Suppressing variable hiding warning in Xcode
- Subject: Re: Suppressing variable hiding warning in Xcode
- From: "Bradley S. O'Hearne" <email@hidden>
- Date: Sun, 5 Apr 2009 19:34:55 -0700
All,
Thanks for the advice. I everyone on the "one extra line of defense"
rationale. I've worked in languages other than Objective C for years
where using variable hiding is common practice, not flagged by the
compiler. But you are right, that is only safe for developers who
NEVER make a programming error. It took me a relatively short amount
of time to rule myself out of the never-had-a-bug club.
Brad
On Apr 5, 2009, at 5:21 PM, Chris Suter wrote:
Hi Brad,
On Mon, Apr 6, 2009 at 10:10 AM, Brad O'Hearne
<email@hidden> wrote:
I had a few questions about selectively suppressing a certain
warning in
Xcode. I personally find the warning which pertains to local
variables
hiding instance variables a real nuisance. For example, if you have a
message signature with a parameter name which matches an instance
variable
name, and the compiler produces the following message:
"warning: local declaration of '<variable name>' hides instance
variable"
Two questions:
1. I get the gist of trying to prevent developers from accidentally
hiding
variables -- but is this really a major problem? Other than this,
is there a
compelling reason to keep this warning in tact, and change variable
parameter variable names to make the warning go away?
2. How do you get Xcode to not produce this warning?
I would urge you not to suppress the warning. It's easy enough to
change one of the names so that they don't clash and it's one more
potential bug (you type the name intending to get the value of the
instance variable but get the parameter instead) you don't have to
worry about.
A lot of people like to prefix their instance variables. Apple use an
underscore which I don't personally like to do because underscore
prefixes tend to be reserved. Other people use different prefixes but
I don't like doing that either because that can complicate things for
KVO and KVC (KVO and KVC know about underscore prefixes).
My personal preference is to prefix the parameter name with either
'a', 'an' or 'the' depending on the context.
If you insist on disabling the warning, "-Wno-shadow" will probably do
the trick. You'd have found that out by looking at the gcc man page.
Kind regards,
Chris
_______________________________________________
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