2.3. 可维护性
<规则1> 在逻辑表达式中使用明确的逻辑判断。
示例:如下逻辑表达式不规范。
1) if ( strlen(strName) )
2) for ( index = MAX_SSN_NUMBER; index ; index -- )
3) while ( p && *p ) // 假设p为字符指针
应改为如下:
1) if ( strlen(strName) != 0 )
2) for ( index = MAX_SSN_NUMBER; index != 0 ; index -- )
3) while ((p != NULL) && (*p != '\0' ))
<规则6> 类的命名
前缀 意义 举例
C 类 CMyClass
CO COM类 COMMyObjectClass
CF COM class factory CFMyClassFactory
I COM interface class IMyInterface
CImpl COM implementation class CImplMyInterface
2、变量的命名:
变量名加前缀,前缀反映变量的数据类型,用小写,反映变量意义的第一个字母大写,其他小写。
其中变量数据类型:
unsigned char 前缀 uc signed char 前缀 sc
unsigned int 前缀 ui signed int 前缀 si
unsigned long 前缀 ul signed long 前缀 sl
bit 前缀 b 指针 前缀 p