What conventions are people here following for naming of instance variables and method arguments - particularly when method arguments are used to set ivars (instance variables)?
In C++ I used to use the m_
prefix for ivars a lot. In C# I followed the convention of disambiguating purely by use of this.
for ivars. I've since adopted the equivalent in C++ too (this->
).
In Objective C I've tried a few things but none have really seemed satisfactory.
Unless someone suggests something really nice I am resigned to the fact that I'll have to compromise (but please, don't make me use the the
prefix for args!), so I'm interested to hear what the majority say - especially from those who have been using ObjC for a while.
I did some due diligence before posting this and a couple of good resources I found where:
- This style guide (briefly mentions my subject)
- This thread (a lot of ex C++ coders in there)
They give me some ideas, but I'm still keen to hear what others are doing.
[edit] Just to clarify: It's specifically how you distinguish ivars from method args that I'm looking for - whether that's through prefixes or some other technique.
[edit 2]
Thanks for all the responses and discussion points. I'm not closing this, but will just say that, as I indicated in my comments to the accepted answer, I've gone with the convention of prefixing init args with the
(and setter args with new
, which I was doing anyway). This seems to be the best balance of forces - even if I'm not keen on the aesthetic myself.