Why do most fields class members in Android tutorial start with m?
Master System Design with Codemia
Enhance your system design skills with over 120 practice problems, detailed solutions, and hands-on exercises.
In Android development, you might have noticed that many field names in tutorials and code samples often begin with the letter m. This is a prevalent naming convention that can initially puzzle those new to the Android ecosystem. In this article, we explore the rationale and history behind this practice, provide technical explanations, and discuss its benefits and potential drawbacks.
The m Prefix: A Remnant of Hungarian Notation
The practice of prefixing class members with m in Android development has its roots in the Hungarian notation system. While the traditional Hungarian notation involves using prefixes to indicate type (e.g., strName for a string), Android and other Java-based projects use a variant called Apps Hungarian or Systems Hungarian. Here, m typically stands for "member" and indicates that the following variable is an instance member of a class.
Understanding the Technical Justifications
- Code Clarity:
Prefacing member variables withmcan help developers quickly distinguish between local variables and class-level fields, particularly in constructor or method bodies. This distinction becomes relevant in constructors where parameters may have similar names to fields.
- Minimizing Scope Confusion:
In complex classes where methods interact with similarly named local variables and fields, usingmenhances readability by reducing ambiguity, thus aiding maintainability and reducing errors. - Encapsulation Reinforcement:
Using a prefix can implicitly communicate that these fields are encapsulated within a class, helping to conceptually separate the data members from method parameters and local scope variables.
Criticism and Alternatives
While this naming convention is widespread, it is not without criticism. Many argue that modern IDEs and tools diminish the necessity of such prefixes by providing advanced contextual information about variables. Moreover, it may not align with Java's increasingly popular camelCase naming conventions.
Alternatives and Modern Practices
thisKeyword:
Usingthisto explicitly refer to class members can alleviate the need for prefixes and provide clarity.
- CamelCase Conventions:
Modern Java practices favor using camelCase without prefixes, aiming for clearer and more intuitive variable names.
Best Practices and Recommendations
- Align with team conventions: Whatever your preference, consistency within your team or project is paramount.
- Consider project complexity: In smaller projects, avoiding prefixes may suffice, but in more extensive codebases, prefixes can support readability.
- Utilize IDE features: Modern development environments provide excellent tools to distinguish variable scopes and assist with refactoring, reducing the need for prefixes.
Summary Table
| Aspect | With m prefix | Without m prefix |
| Distinguishing scope | Easier identification of class fields. Useful in constructors or complex methods. | Relies on this keyword
or IDE features. |
| Readability | Clearer in legacy or large codebases where member distinction is crucial. | Cleaner and more in line with modern camelCase in Java. |
| IDE Support | Less reliance, prefixes provide context. | High reliance on IDE for scope context. |
| Coding standard | Often used in legacy systems or by developers from a C++ background. | Favored in modern Java projects. |
By understanding this naming convention's historical context and technical justification, developers can make informed decisions about whether to follow it in their own projects. While the use of m prefixes remains common in Android tutorials, the landscape continues to evolve, driven by improvements in IDE tooling and shifts in coding standards.

