首页 文章详情

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

面向对象思考 | 357 2020-11-23 18:15 0 0 0
UniSMS (合一短信)

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


新书介绍

《实战Python设计模式》是作者最近出版的新书,拜托多多关注!

本书利用Python 的标准GUI 工具包tkinter,通过可执行的示例对23 个设计模式逐个进行说明。这样一方面可以使读者了解真实的软件开发工作中每个设计模式的运用场景和想要解决的问题;另一方面通过对这些问题的解决过程进行说明,让读者明白在编写代码时如何判断使用设计模式的利弊,并合理运用设计模式。

对设计模式感兴趣而且希望随学随用的读者通过本书可以快速跨越从理解到运用的门槛;希望学习Python GUI 编程的读者可以将本书中的示例作为设计和开发的参考;使用Python 语言进行图像分析、数据处理工作的读者可以直接以本书中的示例为基础,迅速构建自己的系统架构。




觉得本文有帮助?请分享给更多人。

关注微信公众号【面向对象思考】轻松学习每一天!

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



good-icon 0
favorite-icon 0
收藏
回复数量: 0
    暂无评论~~
    Ctrl+Enter