使用空格作为缩进
使用4个空格作为块缩进,不使用“\t”
使用8个空格作为换行,包括函数调用和赋值
正确:
Instrument i =
someLongExpression(that, wouldNotFit, on, one, line);
不正确:
Instrument i =
someLongExpression(that, wouldNotFit, on, one, line);
命名约定
- 非静态,非公共成员变量名以"m"开头
- 静态成员变量名以"s"开始
- 其它成员变量名以一个小写单词开头
- public static final 成员常量 所有字母大写,并用"_"分割单词
例:
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;
}
限制一行代码的长度
在代码中每一行的文字要少于100个字符.(个人猜测:古老的80字符限制在现在越来越大的屏幕上已经不是很适用了)