首页 > 其他 > 详细

代码整洁之道 总结

时间:2015-06-09 20:11:02      阅读:240      评论:0      收藏:0      [点我收藏+]

第二章、有意义的命名


 在给变量、函数、参数、类、包的命名、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;
	}






代码整洁之道 总结

原文:http://blog.csdn.net/changnet/article/details/46428259

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!