-
Notifications
You must be signed in to change notification settings - Fork 9
Coding Guidelines
- Use PascalCase for
identifier
names - Use camelCase for
method
names - Use camelCase for
property names
andlocal variables
- Use whole words in names when possible
Use only "double quotes" for strings
In order to keep the code consistent, please use the following conventions.
From here on good
and bad
are used to attribute things that would make the coding style match, or not match.
We use tabs, not spaces.
good:
public class SubClass extends SuperClass {
public void methodEx() {
// something
}
// something
}
bad:
public class MyClass {
public void myMethod() {
// something
}
// something
}
if:
if (conditional) {
// something
} else if (conditional) {
// something
} else {
// something
}
switch:
switch (a) {
case 'a':
break;
case 'b':
// something
break;
}
for:
for (int i = 0; i < n; i++) {
// something
}
while:
while (conditional) {
// something
}
It is more important to be correct than to be fast.
It is more important to be maintainable than to be fast.
No space before an opening parenthesis when calling methods, or indexing, like this:
method(parameter);
array[];
ArrayList<>;
Do not put a space after the opening parenthesis and the closing one
good:
myMethod(a);
myArray[5];
bad:
myMethod( a );
myArray[ 10 ];
When you use for
, please write statement inside parenthesis like this:
for (int i = 0; i < n; i++){
// something
}
Inside a code block, put the opening brace on the same line
good:
public void methodEx() {
// something
// something
}
ok:
public void methodEx() { code (); }
bad:
public void methodEx()
{
// something
// something
}
Use a space before an opening parenthesis when calling control blocks, like this:
good:
if (conditional) { code(); }
for (;;) { code(); }
switch (a) { code(); }
while (conditional) { code(); }
bad:
if(conditional){code();}
For long, multiline comments use either:
/**
* comment
* Blah
* Blah again
*/
Or:
// Blah
// Blah again
// fin
If there is another tag inside a tag:
good:
<LinearLayout
// something
// something>
<another tag>
<other tag
// something />
</another tag>
</LinerLayout>
bad:
<RelativeLayout
// something
/>
<LinearLayout // something>
</LinearLayout>
<LinearLayout
// something >
</LinearLayout>
otherwise:
good:
<ImageView
// something
// something />
bad:
<Button // something />
<TextView
// something>
</TextView>
<ImageView
// something
// something/>
ok only , , , :
<color name="color">#000000</color>
<dimen name="margin">10dp</dimen>
<string name="string">string</string>
<item name="item">true</item>
Don't use space
good:
android:layout_width="match_parent"
bad:
android: layout_height = "match_parent"