重构(2)判断型函数和判断型变量的命名

主要是针对返回值是bool类型的变量。

普通函数或者工具函数:

    前缀词+名词+动词(is/can/has。。。+something + verb)

  类方法:

      前缀词+名词(is/can/has。。。+something + verb)

几个判断的词汇,分别是,

表示是否符合的状态---  is;

表示是否能够的状态---can;

表示是否应该的状态---should/needs;

表示是否含有的状态---has/include/contains;

判断型变量的命名:

bool bIsTestPassed = false;
bool bShouldUserNameChanged = false;
bool bCanOrder = false;
bool bHasWifi = false;

判断型函数的命名:


bool isUserNameExits(std::string userName)
{
	return false;
}

bool shouldUserNameChanged(std::string userName)
{
	return false;
}

class Hotel
{
public:
	bool hasWifi()
	{
		return false;
	}
	bool canOrdered()
	{
		return false;
	}
};

你可能感兴趣的:(重构)