☰
  • 首页
  • 规则分类
  • 项目介绍
search
•••

全局名称应遵循合理的命名方式

4.1 ID_nameTooShort
目录 › next › previous

全局名称应具有标识性,长度不应过短,否则易与局部名称产生冲突。

本规则是 ID_badName 的特化。

示例:

// In global scope
const int i = 0;     // Non-compliant, name too short
typedef int t;       // Non-compliant, name too short
class A { .... };    // Non-compliant, name too short

int foo(int i) {
    return i + i;    // Confusing
}

名称适用的作用域范围越广,其长度也应该越长,建议全局名称长度不小于 3 个字符。

配置

minVariableNameLength: 全局对象名称长度下限,小于则报出 minFunctionNameLength: 全局函数名称长度下限,小于则报出 minNameSpaceNameLength: 全局命名空间名称长度下限,小于则报出 minTypeNameLength: 全局类型名称长度下限,小于则报出

相关

ID_badName

参考

C++ Core Guidelines NL.7
Copyright©2024 360 Security Technology Inc., Licensed under the Apache-2.0 license.