码迷,mamicode.com
首页 > 其他好文 > 详细

代码整洁之道 总结

时间:2015-06-09 20:12:14      阅读:115      评论:0      收藏:0      [点我收藏+]

标签: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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!