views:

244

answers:

2

AnalysisTool (a Clang GUI front end) states some fo my ivars are improperly named:

Specifically:

the name of instance variable 'groupName' doesn't start with the 'm' prefix

What does the 'm' prefix stand for in Cocoa?

Should I be using it? Or is this a false positive.

+3  A: 

AnalysisTool is a front end GUI, but also uses some custom rules that are not part of Clang. To my knowledge, Clang doesn't enforce/suggest any naming conventions for instance variables, so what you're seeing is probably an in-house coding style (used by the developers of AT) that you can safely ignore. See this SO answer for more details.

The Clang Static Analyzer itself is now available as a binary download for Leopard, whereas previously you had to build it yourself, which was complex and time-consuming. It's fairly easy to use without a GUI, and the reports are pretty nice overall.

Quinn Taylor
I do usually use it from the CL. I was actually having problems due to a linked static library and found AnalysisTool was able to get around them. But any input on the "m" prefix?
Corey Floyd
As I mentioned, I think that's a convention hard-coded into AnalysisTool.
Quinn Taylor
+2  A: 

It's quite common for developers to give the instance variables of their objects names beginning with m_ (short for "member"), and the rule you're seeing shows that your code doesn't conform to that convention. If you don't want to follow this convention in your code, just turn that rule off in the analyser.

Graham Lee
The convention is part of AT, not the Clang tool. In the comments of the SO answer I referenced, the developer of AT acknowledges that some people would like to switch it off, but that feature is not supported in the current version of their GUI tool.
Quinn Taylor
Also, while developers in general may use an "m" or "m_" prefix, I haven't seen that much in Objective-C code, and it seems somewhat unnecessary. Since most variables are instance variables, I use prefixes for statics/globals/constants and make sure local variables don't shadow ivars. Xcode has some pretty decent tools for figuring out where a symbol is declared (Cmd double-click on it) and where it is used (click on it, uses are underlined).
Quinn Taylor
I don't use the convention myself, so don't check for it in the analyser. The Google ObjC coding guide requires it though. Each to their own :-)
Graham Lee
In the age of auto completion, though, forcing lots of variables to be indexed under "m" or "m_" is rather counter-productive. It also smacks of Hungarian-style notation (strSomething, numSomethingElse) which went out of fashion for much the same reason: it forces grouping on variables and methods (getMSomething, setMSomething) for the wrong reasons (visibility, type) rather than the right OO reasons (role or responsibility).
Elise van Looij