NL.8: Use a consistent naming style
NL.8:使用一致的命名方式
Rationale: Consistence in naming and naming style increases readability.
基本原理:命名和命名样式的一致性可以提高可读性。
Note(注意)
There are many styles and when you use multiple libraries, you can't follow all their different conventions. Choose a "house style", but leave "imported" libraries with their original style.
存在很多样式,当您使用多个库时,不可能遵循所有不同的约定。选择一种风格作为“家庭风格”,但保留“导入”库的原始风格。
Example(示例)
ISO Standard, use lower case only and digits, separate words with underscores:
ISO标准仅使用小写字母和数字,并使用下划线分隔单词:
-
int
-
vector
-
my_map
Avoid double underscores __.
避免双重下划线。
Example(示例)
Stroustrup: ISO Standard, but with upper case used for your own types and concepts:
Stroustrup:使用ISO标准,但大写字母用于您自己的类型和概念:
-
int
-
vector
-
My_map
Example(示例)
CamelCase: capitalize each word in a multi-word identifier:
CamelCase:将多单词标识符中的每个字大写:
-
int
-
vector
-
MyMap
-
myMap
Some conventions capitalize the first letter, some don't.
有些约定将首字母大写,有些则没有。
Note(注意)
Try to be consistent in your use of acronyms and lengths of identifiers:
尽量使首字母缩写词和标识符的长度保持一致:
Enforcement(实施建议)
Would be possible except for the use of libraries with varying conventions.
除了使用具有不同约定的库以外,都是可能的。
原文链接
关注微信公众号【面向对象思考】轻松学习每一天!
面向对象开发,面向对象思考!