GCX-HCI / grandcentrix-AndroidCodeStyle

Android code style settings for Android Studio at grandcentrix

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hungarian Notation

passsy opened this issue · comments

From the AOSP Java Code Style 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.

For example:

public class MyClass {
    public static final int SOME_CONSTANT = 42;
    public int publicField;
    private static MyClass sSingleton;
    int mPackagePrivate;
    private int mPrivate;
    protected int mProtected;
}

Our developer survey shows that we overall like the "identifier metadata" and will stick to this convention.
screen shot 2017-08-22 at 21 42 34

We don't believe that "Today, our IDE’s can distinguish all these identifiers with colors so we don’t need any of this any more" because we often read code outside of IDEs when reviewing code.

Cédric Beust outlined his decision to introduce the m-prefix in his article "I am the reason for Hungarian notation in Android". Read this for further arguments for the m-prefix.

Kotlin has no fields (only backing fields) but Properties. The m-Prefix doesn't make sense here. In worst case it would create getters such as getMUser() when calling it from Java.

Don't use the m-Prefix in Kotlin

From the AOSP Java Code Style for Contributors:

ASOP Java Code Style is for Android Open Source contributors, and should not be followed unless you're contributing to Android Open Source Project. I think it's better if the style follows the naming section of Google Java Style