Function module name |
Primary school four arithmetic automatic generation program |
Examiner |
Wang Yuhan |
Review date |
2018.4.17 |
code name |
Primary school four arithmetic automatic generation program |
code author |
Chai Lixuan |
file structure |
importance |
Review item |
in conclusion |
|
Are the names of the header and definition files reasonable? |
Yes |
|
Is the directory structure of header files and definition files reasonable? |
Yes |
|
Are the copyright and version notices complete? |
no |
important |
Does the header file use ifndef/define/endif preprocessor blocks? |
Yes |
|
Whether to store only "declaration" and not "definition" in the header file |
no |
|
|
|
program layout |
importance |
Review item |
in conclusion |
|
Are blank lines appropriate? |
Yes |
|
Are spaces within lines of code decent? |
Yes |
|
Are long line splits decent? |
Yes |
|
Are "{" and "}" on each line and aligned in the same column? |
Yes |
important |
Does a line of code only do one thing? If only one variable is defined, write only one statement. |
Yes |
important |
If, for, while, do and other statements occupy their own line, no matter how many statements are executed, "{}" must be added. |
Yes |
important |
When defining a variable (or parameter), do you place the modifiers * and & right next to the variable name? Are the annotations clear and necessary? |
Yes |
important |
Are the annotations wrong or could lead to misunderstandings? |
no |
important |
Is the public, protected, private order of the class structure consistent across all programs? |
Yes |
|
|
|
naming convention |
importance |
Review item |
in conclusion |
important |
Are the naming conventions consistent with the style of the operating system or development tool used? |
Yes |
|
Are the identifiers intuitive and spellable? |
Yes |
|
The length of the identifier should comply with the "min-length && max-information" principle? |
Yes |
important |
Do the same local variables and all variables appear in the program? |
Yes |
|
Does the writing format of class names, function names, variables and parameters, and constants follow certain rules? |
Yes |
|
Are static variables, global variables, and class member variables prefixed? |
Yes |
|
|
|
Expressions and Basic Statements |
importance |
Review item |
in conclusion |
important |
If there are many operators on a line of code, have parentheses been used to clearly determine the order of operations of the expressions? |
Yes |
|
Are you writing compound expressions that are too complex or multipurpose? |
no |
important |
Confuse compound expressions with "true math expressions"? |
no |
important |
Is the if statement written in an implicitly wrong way? For example |
no |
|
(1) Compare the Boolean variable directly with TRUE, FALSE or 1, 0. |
no |
|
(2) Use "==" or "!=" to compare floating point variables with any number. |
no |
|
(3) Compare the pointer variable with NULL with "==" or "!=". |
no |
|
If there is a logical judgment in the loop body and the number of loops is very large, has the logical judgment been made? |
no |
|
Move to the outside of the loop body? |
no |
important |
Did you forget to add break at the end of the Case statement? |
no |
important |
Did you forget to write the default branch of switch? |
no |
important |
Are there any hidden dangers when using the goto statement? For example, some object construction, variable initialization, important calculations, etc. are skipped. |
no |
|
|
|
constant |
importance |
Review item |
in conclusion |
|
Are you using intuitive constants to represent numbers or strings that will appear multiple times in your program? |
no |
|
In a C++ program, are macro constants replaced by const constants? |
no |
important |
If a constant is closely related to other constants, is that relationship included in the definition? |
no |
|
Are you misunderstanding const data members in classes? Because const data members are only in an object |
no |
|
Constant for lifetime, but mutable for the entire class. |
no |
|
|
|
functional design |
importance |
Review item |
in conclusion |
|
Is the writing of the parameters complete? Don't just write the parameter type and omit the parameter name to save time. |
Yes |
|
参数命名、顺序是否合理? |
是 |
|
参数的个数是否太多? |
否 |
|
是否使用类型和数目不确定的参数? |
否 |
|
是否省略了函数返回值的类型? |
否 |
|
函数名字与返回值类型在语义上是否冲突? |
否 |
重要 |
是否将正常值和错误标志混在一起返回?正常值应当用输出参数获得,而错误标志用return语句返回。 |
否 |
重要 |
在函数体的“入口处”,是否用assert对参数的有效性进行检查? |
否 |
重要 |
使用滥用了assert? 例如混淆非法情况与错误情况,后者是必然存在的并且是一定要作出处理的。 |
否 |
重要 |
return语句是否返回指向“栈内存”的“指针”或者“引用”? |
否 |
|
是否使用const提高函数的健壮性?const可以强制保护函数的参数、返回值,甚至函数的定义体。“Use const whenever you need” |
否 |
|
|
|
内存管理 |
重要性 |
审查项 |
结论 |
重要 |
用malloc或new申请内存之后,是否立即检查指针值是否为NULL?(防止使用指针值为NULL的内存) |
否 |
重要 |
是否忘记为数组和动态内存赋初值?(防止将未被初始化的内存作为右值使用) |
否 |
重要 |
数组或指针的下标是否越界? |
否 |
重要 |
动态内存的申请与释放是否配对?(防止内存泄漏) |
否 |
重要 |
是否有效地处理了“内存耗尽”问题? |
是 |
重要 |
是否修改“指向常量的指针”的内容? |
否 |
重要 |
是否出现野指针?例如(1)指针变量没有被初始化;(2)用free或delete释放了内存之后,忘记将指针设置为NULL。 |
否 |
重要 |
是否将malloc/free 和 new/delete 混淆使用? |
否 |
重要 |
malloc语句是否正确无误?例如字节数是否正确?类型转换是否正 确? |
是 |
重要 |
在创建与释放动态对象数组时,new/delete的语句是否正确无误? |
是 |
|
|
|
C++ 函数的高级特性 |
重要性 |
审查项 |
结论 |
|
重载函数是否有二义性? |
否 |
重要 |
是否混淆了成员函数的重载、覆盖与隐藏? |
否 |
|
运算符的重载是否符合制定的编程规范? |
是 |
|
是否滥用内联函数?例如函数体内的代码比较长,函数体内出现循环。 |
否 |
重要 |
是否用内联函数取代了宏代码? |
否 |
|
|
|
类的构造函数、析构函数和赋值函数 |
重要性 |
审查项 |
结论 |
重要 |
是否违背编程规范而让C++ 编译器自动为类产生四个缺省的函数: |
否 |
|
(1)缺省的无参数构造函数; |
否 |
|
(2)缺省的拷贝构造函数; |
否 |
|
(3)缺省的析构函数; |
否 |
|
(4)缺省的赋值函数。 |
否 |
重要 |
构造函数中是否遗漏了某些初始化工作? |
否 |
重要 |
是否正确地使用构造函数的初始化表? |
否 |
重要 |
析构函数中是否遗漏了某些清除工作? |
否 |
|
是否错写、错用了拷贝构造函数和赋值函数? |
否 |
重要 |
赋值函数一般分四个步骤: |
|
|
(1)检查自赋值; |
否 |
|
(2)释放原有内存资源; |
否 |
|
(3)分配新的内存资源,并复制内容; |
否 |
|
(4)返回 *this。是否遗漏了重要步骤? |
无 |
重要 |
是否正确地编写了派生类的构造函数、析构函数、赋值函数? |
无 |
|
注意事项: |
|
|
(1)派生类不可能继承基类的构造函数、析构函数、赋值函数。 |
无 |
|
(2)派生类的构造函数应在其初始化表里调用基类的构造函数。 |
无 |
|
(3)基类与派生类的析构函数应该为虚(即加virtual关键字)。 |
无 |
|
(4)在编写派生类的赋值函数时,注意不要忘记对基类的数据成员重新赋值 |
无 |
|
|
|
类的高级特性 |
重要性 |
审查项 |
结论 |
重要 |
是否违背了继承和组合的规则? |
否 |
无 |
(1)若在逻辑上B是A的“一种”,并且A的所有功能和属性对B而言都有意义,则允许B继承A的功能和属性。 |
无 |
|
(2)若在逻辑上A是B的“一部分”(a part of),则不允许B从A派生,而是要用A和其它东西组合出B。 |
否 |
无 |
|
|
其它常见问题 |
重要性 |
审查项 |
结论 |
重要 |
数据类型问题: |
否 |
|
(1)变量的数据类型有错误吗? |
否 |
|
(2)存在不同数据类型的赋值吗? |
否 |
|
(3)存在不同数据类型的比较吗? |
否 |
重要 |
变量值问题: |
否 |
|
(1)变量的初始化或缺省值有错误吗? |
否 |
|
(2)变量发生上溢或下溢吗? |
否 |
|
(3)变量的精度够吗? |
是 |
重要 |
逻辑判断问题: |
是 |
|
(1)由于精度原因导致比较无效吗? |
否 |
|
(2)表达式中的优先级有误吗? |
否 |
|
(3)逻辑判断结果颠倒吗? |
否 |
重要 |
循环问题: |
否 |
|
(1)循环终止条件不正确吗? |
否 |
|
(2)无法正常终止(死循环)吗? |
否 |
|
(3)错误地修改循环变量吗? |
否 |
|
(4)存在误差累积吗? |
否 |
重要 |
错误处理问题: |
|
|
(1)忘记进行错误处理吗? |
否 |
|
(2)错误处理程序块一直没有机会被运行? |
否 |
|
(3)错误处理程序块本身就有毛病吗?如报告的错误与实际错误不一致,处理方式不正确等等。 |
否 |
|
(4)错误处理程序块是“马后炮”吗?如在被它被调用之前软件已经出错。 |
否 |
重要 |
文件I/O问题: |
|
|
(1)对不存在的或者错误的文件进行操作吗? |
否 |
|
(2)文件以不正确的方式打开吗? |
否 |
|
(3)文件结束判断不正确吗? |
否 |
|
(4)没有正确地关闭文件吗? |
否 |
|
|
|