标签:java
第二章、有意义的命名
在给变量、函数、参数、类、包的命名、jar包、war包、ear文件的命名都需要一个好的命名。
1、名副其实(名声或名义和实际相符)
变量
// 不推荐 int d ; //消失的时间,以日计 // 推荐 int elapsedTimeInDays;
方法
// 不推荐的写法
public List<int[]> getThem( List<int[]> theList){
List<int[]> list1 = new ArrayList<int[]>();
for(int[] x : theList){
if(x[0] ==4){
list1.add(x);
}
}
return list1;
}
// 存在的问题点
// 1、theList 零下标的意义是什么?
// 2、值4的意识是什么?
// 3、我怎么使用返回的列表?
// 4、这个方法是要处理什么的?
//推荐
public List<Cell> getFlaggedCells(List<Cell> getBoard){
List<Cell> faggedCells = new ArrayList<Cell>();
for(Cell cell : getBoard){
if(cell.isFlagged()){
faggedCells.add(cell);
}
}
return faggedCells;
}
标签:java
原文地址:http://blog.csdn.net/changnet/article/details/46428259