Looking at the Android tutorials such as the Notepad tutorial, I noticed that almost all variables are named starting with the letter 'm'. What convention is this, and where does it originate from?
It stands for member. I personally find this convention unhelpful, but it's subjective.
this
? The whole point of that keyword is to indicate you're dealing with a class member variable/function. –
Tormentil this
does indicate that what follows is a member but I wouldn't clutter my code with that either. If you right short methods, whether a variable is local or a member shouldn't be confusing. Only prefix with this.
when it's needed to disambiguate. –
Seldan 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."
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.
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)
'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 its name.
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
'm' means the variable is a member variable of the class...
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.
© 2022 - 2024 — McMap. All rights reserved.