前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >C++核心准则​NL.8:使用一致的命名方式

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

作者头像
面向对象思考
发布2020-11-26 11:16:09
3200
发布2020-11-26 11:16:09
举报
文章被收录于专栏:C++核心准则原文翻译

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:

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

代码语言:javascript
复制
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

本文参与 腾讯云自媒体同步曝光计划,分享自微信公众号。
原始发表:2020-11-23,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 面向对象思考 微信公众号,前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • NL.8: Use a consistent naming style
    • Example(示例)
      • Enforcement(实施建议)
      领券
      问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档