Why do variable names often start with the letter 'm'? [duplicate]

0 votes
asked Nov 21, 2010 by kallja

This question already has an answer here:

9 Answers

0 votes
answered Nov 21, 2010 by swcai

'm' means the variable is a member variable of the class...

0 votes
answered Nov 21, 2010 by matthew-flaschen

It stands for member. I personally find this convention unhelpful, but it's subjective.

0 votes
answered Nov 21, 2010 by vladimir-ivanov

'm' means member of the class. So, if you don't use IDE to highlight your members, then you will understand that it is a member by it's name

0 votes
answered Nov 21, 2010 by stacker

As already answered this prefix indcates that a variable is member.

Somtimes people use other prefixes if you discover some variables starting with 'i' or 's' it could also be a variant of the Hungarian Notation

0 votes
answered Nov 12, 2011 by chunkyguy

not only in java, I've seen similar convention in cocos2d+box2d samples where some of the variables start with m_, but others don't, very confusing.


b2World* world;
GLESDebugDraw *m_debugDraw;

I guess to differentiate C++ box2d variables from Obj-C variables.

0 votes
answered Nov 14, 2011 by warren-chu

See Code Style Guidelines for Contributors: Follow Field Naming Conventions. The use of the "m" prefix is more specific that simply denoting a "member" variable: It's for "non-public, non-static field names."

0 votes
answered Nov 16, 2014 by chris-catignani

I come across this convention from time to time and have to agree that its pretty useless. Stacker mentions Hungarian Notation...that is my preference.

private string sName;
public string Name
{
    get { return sName; }
    set { sName = value; }
}

This way it show the type and its differentiated from the method name.

0 votes
answered Nov 15, 2015 by danilodughetti

According to Android source code documentation:

  • Non-public, non-static field names start with m.
  • Static field names start with s.
  • Other fields start with a lower case letter.
  • Public static final fields (constants) are ALL_CAPS_WITH_UNDERSCORES.

Note that this is for writing Android source code. For creating Android apps, the Google Java Style Guide may be more helpful.

0 votes
answered Nov 16, 2015 by klaus

The m is here to indicate a member variable.

It has 2 huge advantages:

  • If you see it, you instantly recognize it as a member variable.
  • Press m and you get all members via the auto completer. (This one is not in the other answers)
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
Website Online Counter

...