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

Use Android field naming convention or Java's? #986

Closed
EmmanuelMess opened this issue Feb 2, 2018 · 5 comments
Closed

Use Android field naming convention or Java's? #986

EmmanuelMess opened this issue Feb 2, 2018 · 5 comments
Labels
Issue-Discussion Deprecated: use discussions tab.

Comments

@EmmanuelMess
Copy link
Member

From 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;
}

And from Java Code Conventions:

Identifier Type Rules for Naming Examples
Variables Except for variables, all instance, class, and class constants are in mixed case with a lowercase first letter. Internal words start with capital letters. Variable names should not start with underscore _ or dollar sign $ characters, even though both are allowed.

Variable names should be short yet meaningful. The choice of a variable name should be mnemonic- that is, designed to indicate to the casual observer the intent of its use. One-character variable names should be avoided except for temporary "throwaway" variables. Common names for temporary variables are i, j, k, m, and n for integers; c, d, and e for characters.
int i;
char c;
float myWidth;

I personally prefer the second one, because of less clutter. But right now we have both, so which one should be enforced?

@EmmanuelMess EmmanuelMess added the Issue-Discussion Deprecated: use discussions tab. label Feb 2, 2018
@TranceLove
Copy link
Collaborator

I used to code the Java way, so I'd vote for Java's coding convention. My previous work was in AOSP's coding style because - just to make sure I'm with Android's standard to reduce the chance of the PR being rejected.

(Though, what happened then was not related to naming conventions at all ;))

@tryton-vanmeer
Copy link

I also prefer the second one when writing Java code. Jake Wharton also has a good post on the subject.

@EmmanuelMess
Copy link
Member Author

EmmanuelMess commented Feb 7, 2018

Well, I'll use Java notation on new PRs (as always) and enforce the usage of Java notation in new PRs. That is if no one proposes a counter argument.

@VishalNehra
Copy link
Member

VishalNehra commented Feb 7, 2018

I used to follow the AOSP style. However, Jake does have a point in the article mentioned by @tryton-vanmeer

TranceLove added a commit to TranceLove/AmazeFileManager that referenced this issue Feb 9, 2018
Fixes TeamAmaze#1003. Also changed member naming back to Java's coding convention (TeamAmaze#986)
TranceLove added a commit to TranceLove/AmazeFileManager that referenced this issue Feb 9, 2018
@EmmanuelMess
Copy link
Member Author

It's decided then.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Discussion Deprecated: use discussions tab.
Projects
None yet
Development

No branches or pull requests

4 participants