命名联合或提升::变体类型定义
Naming union or boost::variant typedefs
我在一个变体中保存数据库值。在您看来,以下哪种类型定义最有意义:
typedef boost::variant<int, bool, std::string> Value;
typedef boost::variant<int, bool, std::string> Values;
typedef boost::variant<int, bool, std::string> Type;
typedef boost::variant<int, bool, std::string> Types;
它们都没有意义。值或类型是什么意思?只是抽象的名字。最好用更具体的名字来命名它们,例如ObjectState或PacketField。像Type这样的名称没有任何意义,当你命名你的变量时,认为其他人可以阅读和理解它的含义,当你忘记你做了什么时,你必须记住它是什么,不要阅读一堆代码来理解这种类型的用途。
有关变量命名和软件工程的更多信息,您可以购买由Steve McConnell撰写的精彩书籍Code Complete。
相关文章:
- 有没有一种方法可以通过"typedef"为重新定义的基本类型定义特征和强制转换运算符
- 强枚举类型定义:Clang Bug 还是 C++11 标准不确定性?
- 列表参数的类型定义
- 使用模板化的键类型定义 std::map,该键类型基于作为参数接收的函数
- 关于 C++ 中的函数类型定义
- C++(和 ROS) - 包含与前向声明引用,设置默认值和类型定义
- 将使用/类型定义限制为类范围
- 模板类型定义?
- C++:模板类的类型定义
- 如何对命名空间限定类型进行类型定义?
- 此递归模板类型定义是否有效C++?
- 具有调整对齐方式的类型定义
- C++从抽象类型定义类成员
- 用于C++代码的 API 监视器类型定义 (XML)
- 如何将result_of与函数类型定义一起使用
- 在C++的适当类型定义位置
- 如何根据模板类型定义浮点常量?
- 如何为缺少预定义运算符而不扩展命名空间"std"的标准类型定义运算符>> (istream &, ...)?
- 参数化类的别名(或类型定义)内部类
- 如果我想从类型"T"定义元素的容器(来自 STL),那么"T"必须使用默认构造函数?