Why Do Most Fields (Class Members) in Android Tutorial Start with 'M'

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

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.

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

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

Android programming m before objects

Follow Field Naming Conventions

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

You can see the document on those rules here.

Why does this Android developer doc name some of its variables with TWO m's

I don't know for sure, but I suspect it is meant to signify a sub-class private non-static variable.

Which field names get prefix 'm'?

In your second example, mMethodFieldOne and mMethodFieldTwo are not fields, just variables local to someMethod, so the naming convention does not apply.

What does mInflator stand for?

m stands for "member". it is a convention for naming member variables. They are variables defined outside of any methods but inside the class and are used in different methods. member variables often said as fields in java / android studio



Related Topics



Leave a reply



Submit