首页 > 编程语言 > 详细

C++学习笔记5:如何给变量及函数命名?

时间:2016-12-03 01:56:20      阅读:248      评论:0      收藏:0      [点我收藏+]

1.遵循C++规定的变量及函数命名方法;

2.原则:简单,易于理解;

以下是一些例子,可以作为参考:

//bad examples:
int ccount;//Nobody knows what a ccount is.
int i;//Generally bad unless use is trivial or temporary, such as loop variables.
int _count;//don‘t start variable names with underscore.
int data;//What kind of data?
int value1,value2;//Can be hard to differentiate between the two?
int x,y;//generally bad unless use is trivial, such as in trivial mathematical functions.

//good examples:
int customerCount;//clear what we‘re counting
int index;//okay if obvious what we‘re indexing
int totalScore;//good descriptive
int numberOfApples;//descriptive
int monstersKilled;//descriptive

 

C++学习笔记5:如何给变量及函数命名?

原文:http://www.cnblogs.com/hujianglang/p/6127551.html

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