Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do most fields (class members) in Android tutorial start with `m`?

I know about camel case rules, but I'm confused with this m rule. What does it stand for? I'm a PHP developer. "We" use first letters of variables as indication of type, like 'b' for boolean, 'i' for integer and so on.

Is 'm' a Java thing? Does it stand for mobile? mixed?

like image 763
pambuk Avatar asked Jan 19 '10 08:01

pambuk


People also ask

Why do Android variables start with m?

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.

What's another name for a member variable or data member?

Member variables in a class—these are called fields. Variables in a method or block of code—these are called local variables. Variables in method declarations—these are called parameters.

Where is method called in Android Studio?

In Android Studio, highlight the method and either right click > Find usages or use the Alt + F7 shortcut.


1 Answers

This notation comes from AOSP (Android Open Source Project) Code Style Guidelines for Contributors:

Follow Field Naming Conventions

  • 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 the linked style guide is for code to be contributed to the Android Open Source Project.

It is not a style guide for the code of individual Android apps.

like image 155
xiaobing.zhao Avatar answered Oct 12 '22 02:10

xiaobing.zhao