Skip to content

Code Style

Natalia Jastrzębska edited this page Nov 11, 2017 · 9 revisions

GENERAL

  1. Do not use hardcoded strings. Use values/strings.xml to store string resources.
+ do
        android:text="@string/hello_world"
        textView.setText(R.string.great);

- don't
        android:text="Hello World"
        textView.setText("So bad!");
  1. Do not use hardcoded values for text size, margins, paddings, etc. Use dimens.xml instead.
+ do
        android:textSize="@dimen/base_text_size"
        android:layout_marginTop="@dimen/base_margin"

- don't
        android:layout_marginTop="16dp"
        android:textSize="16sp"

VERTICAL SPACES

1. return statement

  • if there is only return statement in method, no need to make empty line before.
+ do
public int getSize() {
   return this.size;
}
  • if there is more than return statement, then make an empty line before
+ do
public int getModifiedSize() {
   int modifiedSize = this.size + this.modifier;
   
   return modifiedSize;
}

Clone this wiki locally