Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hungarian Notation #4

Closed
passsy opened this issue Sep 26, 2017 · 2 comments
Closed

Hungarian Notation #4

passsy opened this issue Sep 26, 2017 · 2 comments

Comments

@passsy
Copy link
Contributor

passsy commented Sep 26, 2017

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.

@passsy passsy closed this as completed Sep 26, 2017
@passsy
Copy link
Contributor Author

passsy commented Sep 26, 2017

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

@vincent-paing
Copy link

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

Rainer-Lang added a commit to Rainer-Lang/AndroidCodeStyle that referenced this issue Oct 8, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants