2012-10-11 58 views
0

我在变量中保存数据库值。您认为以下哪种typedefs最符合您的意见:命名union或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; 

回答

3

没有一个含义。什么是价值观或类型?只是抽象的名字。更好地命名它们更具体,例如ObjectState或PacketField。像Type这样的名字意味着什么,当你给变量命名时,认为其他人可以阅读和理解它的含义,当你忘记了你做了什么时,你必须记住它是什么,并且不要阅读一堆代码来理解这种类型。

有关变量命名和更多关于软件工程的更多信息,您可以购买由Steve McConnell编写的精彩图书Code complete

+0

有人可能会说,ObjectState和PacketField几乎没有比Value/Type更多的含义......它们只是更长。 – ltjax