(5)、PropertyMap:boost/property_map.hpp
(6)、Iterator中处理迭代器定义的部分:boost/iterator/iterator_adaptor.hpp,boost/iterator/iterator_facade.hpp,以及boost/function_output_iterator.hpp
我们正在积极考虑增加其它Boost特性,所以列表中的规则将不断变化.
6.命名约定:
最重要的一致性规则是命名管理.命名风格快速获知名字代表是什么东东:类型?变量?函数?常量?宏...?甚至不需要去查找类型声明.我们大脑中的模式匹配引擎可以非常可靠的处理这些命名规则.
命名规则具有一定随意性,但相比按个人喜好命名,一致性更重,所以不管你怎么想,规则总归是规则.
通用命名规则:函数命名,变量命名,文件命名应具备描述性;不要过度缩写.类型和变量应该是名词,函数名可以用“命令性”动词.
如何命名:尽可能给出描述性的名称.不要节约行空间,让别人很快理解你的代码更重要.好的命名风格:
int num_errors; // Good. int num_completed_connections; // Good.糟糕的命名使用含糊的缩写或随意的字符:
int n; // Bad - meaningless. int nerr; // Bad - ambiguous abbreviation. int n_comp_conns; // Bad - ambiguous abbreviation.类型和变量名一般为名词:如FileOpener, num_errors.
函数名通常是指令性的(确切的说它们应该是命令),如OpenFile(),set_num_errors().取值函数是个特例(在函数命名处详细阐述),函数名和它要取值的变量同名.
缩写:除非该缩写在其它地方都非常普遍,否则不要使用.例如:
// Good // These show proper names with no abbreviations. int num_dns_connections; // 大部分人都知道 "DNS" 是啥意思. int price_count_reader; // OK, price count. 有意义.Warning:
// Bad! // Abbreviations can be confusing or ambiguous outside a small group. int wgc_connections; // Only your group knows what this stands for. int pc_reader; // Lots of things can be abbreviated "pc".永远不要用省略字母的缩写:
int error_count; // Good. int error_cnt; // Bad.文件命名:文件名要全部小写,可以包含下划线(_)或连字符(-).按项目约定来.
可接受的文件命名:
my_useful_class.cc my-useful-class.cc myusefulclass.ccC++文件要以.cc结尾,头文件以.h结尾.
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/jisuanjixue/article-35033-17.html
大国崛起过程