代码规范五条规则
Table of Contents
1 全部的语句块都必须用{}包围,即便如if,for下只有一条语句。
1.1 Demo
推荐: css
for (int i=0;i<10 ;i++ ) { excute (); }
不推荐: html
for (int i=0;i<10 ;i++ ) excute ();
2 括号的形式采用悬挂式风格
2.1 demo
推荐: java
public static void main(String[] args) { doSomeThing (); }
不推荐: eclipse
public static void main(String[] args) { doSomeThing (); }
3 代码的tab缩进为4个字符
3.1 demo
推荐(eclipse 能够百度搜索下更改默认缩进的位数) 函数
public static void main(String[] args) { System.out.println("this is a tab width example!"); }
不推荐 post
public static void main(String[] args) { System.out.println("this is a tab width example!"); }
4 一个方法的CyclomaticComplexity(圈复杂度)不超过10
4.1 说明
圈复杂度指一个方法的独立路径的数量,能够用一个方法内if,while,do,for,catch,switch,case,?:语句与&&,||操做符的总个数来度量。 尽可能控制一个方法的复杂程度 this
4.2 demo
看说明,你们都懂得 spa
5 控制每行代码的长度,每行代码不要超过120个字符
5.1 说明
一行中含有太多的字符会大大下降代码的可读性,须要控制每一行代码的字符数。 暂定上线为120个字符。超过的时候须要考虑写下小函数拆分或者换行了。 代码规范