C++核心准则​NL.8:使用一致的命名方式

网友投稿 866 2022-10-12

C++核心准则​NL.8:使用一致的命名方式

C++核心准则​NL.8:使用一致的命名方式

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:

尽量使首字母缩写词和标识符的长度保持一致:

int mtbf {12};int mean_time_between_failures {12}; // make up your mind

Enforcement(实施建议)

Would be possible except for the use of libraries with varying conventions.

除了使用具有不同约定的库以外,都是可能的。

原文链接

​​https://github.com/isocpp/CppCoreGuidelines/blob/master/CppCoreGuidelines.md#nl8-use-a-consistent-naming-style​​

面向对象开发,面向对象思考!

版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。

上一篇:SpringCloud项目的log4j2漏洞解决方案详解流程
下一篇:简单的PWA小程序,可离线加载,可添加到桌面屏幕
相关文章

 发表评论

暂时没有评论,来抢沙发吧~