ES.8: Avoid similar-looking names
ES.8:避免看起来差不多的名称
Reason(原因)
Code clarity and readability. Too-similar names slow down combiiaoprehension and increase the likelihood of error.
代码整洁性和可读性。过于相似的名称会减缓理解进程并增加出错的可能性。
Example, bad(反面示例)
Example, bad(反面示例)
Do not declare a non-type with the same name as a type in the same scope. This removes the need to disambiguate with a keyword such as struct or enum. It also removes a source of errors, as struct X can implicitly declare X if lookup fails.
不要用一个名称定义类型之后,在同一个作用域中又使用这个名称定义非类型。这种做法使消除名称和像struct或enum那样的关键词之间的歧义不再必要。同时也减少了一个错误的源头,例如如果名称检索失败,struct X可以隐性声明X类型。
Exception(例外)
Antique header files might declare non-types and types with the same name in the same scope.
特别早期的头文件可能会使用同一个名称声明类型和非类型。
Enforcement(实施建议)
- Check names against a list of known confusing letter and digit combinations.
- 使用一个已知的容易混淆的字母和数字的列表检查名称。
- Flag a declaration of a variable, function, or enumerator that hides a class or enumeration declared in the same scope.
- 标记同一作用域中可能隐藏类或枚举类型声明的变量、函数、枚举类型的声明。
原文链接
https:///isocpp/CppCoreGuidelines/blob/master/#es8-avoid-similar-looking-names
觉得本文有帮助?欢迎点赞并分享给更多的人。
阅读更多更新文章,请关注微信公众号【面向对象思考】
















