<font face="黑体" color=#00FFFF>代码复审</font>
###<font face="黑体" color=#FF0000>Partner's ProjectAddress</font>
项目功能
<font face="宋体"> 此项目为张天翊同学所写,其功能如下:</font> <font face="宋体"> 通过四个数字的形式输入起始坐标点,可以分别调用中点画线法,dda和BresenHam三个绘制直线的模块,都会返回需要点亮的坐标。</font>
项目代码
def midPointLine(x0=-1,y0=0,x1=5,y1=4):
points = []
x0 = int(x0); y0 = int(y0)
x1 = int(x1); y1 = int(y1)
if x0 > x1:
x0, x1 = x1, x0
y0, y1 = y1, y0
print('x', 'y')
a = y0 - y1
b = x1 - x0
c = x0 * y1 - x1 * y0
x = x0; y = y0
k = (y0 - y1)/(x0 - x1)
if x0 == 0 and x1 == 0 :
for i in range(min(y0, y1), max(y0, y1) + 1, 1):
print(0, i)
points.append((0, i))
elif y0 == 0 and y1 == 0:
for i in range(min(x0, x1), max(x0, x1) + 1, 1):
print(i, 0)
points.append((i, 0))
elif k == 1:
for i in range(min(x0, x1), max(x0, x1) + 1, 1):
print(i, i)
points.append((i, i))
elif k == -1:
for i in range(min(x0, x1), max(x0, x1) + 1, 1):
print(i, -i)
points.append((i, -i))
elif k > 0 and k < 1:
d0 = 2*a + b
d1 = 2*a
d2 = 2*(a + b)
print(x, y)
points.append((x, y))
while x < x1:
if d0 < 0:
x += 1
y += 1
d0 += d2
else:
x += 1
d0 += d1
print(x, y)
points.append((x, y))
elif k > 1:
d0 = a + 2*b
d1 = 2*(a + b)
d2 = 2*b
print(x, y)
points.append((x, y))
while y < y1:
if d0 > 0:
x += 1
y += 1
d0 += d1
else:
y += 1
d0 += d2
print(x, y)
points.append((x, y))
elif k < -1:
d0 = a - 2*b
d1 = -2*b
d2 = 2*(a - b)
print(x, y)
points.append((x, y))
while y > y1:
if d0 < 0:
x += 1
y -= 1
d0 += d2
else:
y -= 1
d0 += d1
print(x, y)
points.append((x, y))
elif k > -1 and k < 0:
d0 = 2*a - b
d1 = 2*(a - b)
d2 = 2*a
print(x, y)
points.append((x, y))
while x < x1:
if d0 > 0:
x += 1
y -= 1
d0 += d1
else:
x += 1
d0 += d2
print(x, y)
points.append((x, y))
return points
def dda(x1=5, y1=12, x2=0, y2=0):
points = []
x1 = int(x1); y1 = int(y1)
x2 = int(x2); y2 = int(y2)
print('x', 'y')
print(x1, y1)
points.append((x1, y1))
if x1 == 0 and x2 == 0 :
for i in range(min(y1, y2), max(y1, y2) + 1, 1):
print(0, i)
points.append((0, i))
elif y1 == 0 and y2 == 0:
for i in range(min(x1, x2), max(x1, x2) + 1, 1):
print(i, 0)
points.append((i, 0))
else:
dx = x2 - x1; dy = y2 - y1
x = x1; y = y1
ep = max(abs(dx), abs(dy))
xIn = dx / ep; yIn = dy / ep
for i in range(0, ep + 1, 1):
print(int(x + 0.5), int(y + 0.5))
points.append((int(x + 0.5), int(y + 0.5)))
x += xIn
y += yIn
return points
def bresenHam(x1=-5, y1=1, x2=4, y2=-2):
if x1 > x2:
x1, x2 = x2, x1
y1, y2 = y2, y1
dx = x2 - x1
dy = y2 - y1
k = dy / dx
e = -0.5
x = x1; y = y1
points = []
print('x', 'y')
if x1 == 0 and x2 == 0:
for i in range(min(y1, y2), max(y1, y2) + 1, 1):
print(0, i)
points.append((0, i))
elif y1 == 0 and y2 == 0:
for i in range(min(x1, x2), max(x1, x2) + 1, 1):
print(i, 0)
points.append((i, 0))
elif k == 1:
for i in range(min(x1, x2), max(x1, x2) + 1, 1):
print(i, i)
points.append((i, i))
elif k == -1:
for i in range(min(x1, x2), max(x1, x2) + 1, 1):
print(i, -i)
points.append((i, -i))
elif k > 0 and k < 1:
for i in range(0, abs(dx)+1, 1):
print(x, y)
points.append((x, y))
x += 1
e += k
if e >= 0:
y += 1
e -= 1
elif k > 1:
for i in range(0, abs(dy)+1, 1):
print(x, y)
points.append((x, y))
y += 1
e += 1/k
if e >= 0:
x += 1
e -= 1
elif k < -1:
for i in range(0, abs(dy)+1, 1):
print(x, y)
points.append((x, y))
y -= 1
e += 1/k
if e <= -1:
x += 1
e += 1
elif k > -1 and k < 0:
for i in range(0, abs(dx)+1, 1):
print(x, y)
points.append((x, y))
x += 1
e += k
if e <= -1:
y -= 1
e += 1
return points
if __name__ == "__main__":
pass
代码审查表
<table border="0" cellspacing="0" cellpadding="0"><colgroup><col width="110" /><col width="620" /><col width="82" /><col width="262" /></colgroup><tbody><tr><td class="xl66" width="110" height="19">模块名称</td> <td class="xl83" colspan="3" width="964">图形学绘制直线的三个方法 </td> </tr><tr><td class="xl67" width="110" height="19">审查人</td> <td class="xl72" width="620">张家铭 </td> <td class="xl68" width="82">审查日期</td> <td class="xl69">2019.4.22 </td> </tr><tr><td class="xl67" width="110" height="19">代码名称</td> <td class="xl72" width="620">CG.py </td> <td class="xl68" width="82">代码作者</td> <td class="xl69">张天翊 </td> </tr><tr><td class="xl86" colspan="4" height="19">文件结构</td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">头文件和定义文件的名称是否合理?</td> <td class="xl81" colspan="2">符合python库引用方式 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl73" width="620">头文件和定义文件的目录结构是否合理?</td> <td class="xl81" colspan="2">合理 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl73" width="620">版权和版本声明是否完整?</td> <td class="xl81" colspan="2">并无版权和版本申明 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">头文件是否使用了 ifndef/define/endif 预处理块?</td> <td class="xl81" colspan="2">无预处理块 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">头文件中是否只存放“声明”而不存放“定义”</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">程序的版式</td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">空行是否得体?</td> <td class="xl81" colspan="2">程序空行较为得体 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">代码行内的空格是否得体?</td> <td class="xl81" colspan="2">较为得体 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">长行拆分是否得体?</td> <td class="xl81" colspan="2">得体 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">“{” 和 “}” 是否各占一行并且对齐于同一列?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">一行代码是否只做一件事?如只定义一个变量,只写一条语句。</td> <td class="xl81" colspan="2">存在部分语句过于冗余 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">If、for、while、do等语句自占一行,不论执行语句多少都要加 “{}”。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="38">重要</td> <td class="xl72" width="620">在定义变量(或参数)时,是否将修饰符 * 和 & 紧靠变量名?注释是否清晰并且必要?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">注释是否有错误或者可能导致误解?</td> <td class="xl81" colspan="2">注释过少 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">类结构的public, protected, private顺序是否在所有的程序中保持一致?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">命名规则 </td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">命名规则是否与所采用的操作系统或开发工具的风格保持一致?</td> <td class="xl81" colspan="2">较为符合命名规则 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">标识符是否直观且可以拼读?</td> <td class="xl81" colspan="2">标识符较为直观 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">标识符的长度应当符合“min-length && max-information”原则?</td> <td class="xl81" colspan="2">符合 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">程序中是否出现相同的局部变量和全部变量?</td> <td class="xl81" colspan="2">是 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">类名、函数名、变量和参数、常量的书写格式是否遵循一定的规则?</td> <td class="xl81" colspan="2">无类 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">静态变量、全局变量、类的成员变量是否加前缀?</td> <td class="xl81" colspan="2">并没有添加前缀 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">表达式与基本语句 </td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">如果代码行中的运算符比较多,是否已经用括号清楚地确定表达式的操作顺序?</td> <td class="xl81" colspan="2">并没有使用括号 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否编写太复杂或者多用途的复合表达式?</td> <td class="xl81" colspan="2">没有编写 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否将复合表达式与“真正的数学表达式”混淆?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否用隐含错误的方式写if语句? 例如</td> <td class="xl81" colspan="2">没有 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)将布尔变量直接与TRUE、FALSE或者1、0进行比较。</td> <td class="xl81" colspan="2">没有 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)将浮点变量用“==”或“!=”与任何数字比较。</td> <td class="xl81" colspan="2">没有 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)将指针变量用“==”或“!=”与NULL比较。</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">如果循环体内存在逻辑判断,并且循环次数很大,是否已经将逻辑判</td> <td class="xl81" colspan="2">无此情况 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">断移到循环体的外面?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">Case语句的结尾是否忘了加break?</td> <td class="xl81" colspan="2">无Case语句 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否忘记写switch的default分支?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="38">重要</td> <td class="xl72" width="620">使用goto 语句时是否留下隐患? 例如跳过了某些对象的构造、变量的初始化、重要的计算等。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">常量 </td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否使用含义直观的常量来表示那些将在程序中多次出现的数字或字符串?</td> <td class="xl81" colspan="2">使用 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">在C++ 程序中,是否用const常量取代宏常量?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">如果某一常量与其它常量密切相关,是否在定义中包含了这种关系?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否误解了类中的const数据成员?因为const数据成员只在某个对象</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">生存期内是常量,而对于整个类而言却是可变的。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">函数设计 </td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">参数的书写是否完整?不要贪图省事只写参数的类型而省略参数名字。</td> <td class="xl81" colspan="2">参数书写完整 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">参数命名、顺序是否合理?</td> <td class="xl81" colspan="2">参数命名,顺序合理 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">参数的个数是否太多?</td> <td class="xl81" colspan="2">参数的个数正常 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否使用类型和数目不确定的参数?</td> <td class="xl81" colspan="2">没有使用类型和数目不确定的参数 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否省略了函数返回值的类型?</td> <td class="xl81" colspan="2">是 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">函数名字与返回值类型在语义上是否冲突?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="38">重要</td> <td class="xl72" width="620">是否将正常值和错误标志混在一起返回?正常值应当用输出参数获得,而错误标志用return语句返回。</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">在函数体的“入口处”,是否用assert对参数的有效性进行检查?</td> <td class="xl81" colspan="2">并没有对入口参数做非法检查 </td> </tr><tr><td class="xl71" height="38">重要</td> <td class="xl72" width="620">使用滥用了assert? 例如混淆非法情况与错误情况,后者是必然存在的并且是一定要作出处理的。</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">return语句是否返回指向“栈内存”的“指针”或者“引用”?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="38"> </td> <td class="xl72" width="620">是否使用const提高函数的健壮性?const可以强制保护函数的参数、返回值,甚至函数的定义体。“Use const whenever you need”</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl86" colspan="4" height="19">内存管理 </td> </tr><tr><td class="xl79" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl80" height="38">重要</td> <td class="xl72" width="620">用malloc或new申请内存之后,是否立即检查指针值是否为NULL?(防止使用指针值为NULL的内存)</td> <td class="xl92" colspan="2"> </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">是否忘记为数组和动态内存赋初值?(防止将未被初始化的内存作为右值使用)</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">数组或指针的下标是否越界?</td> <td class="xl92" colspan="2">否 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">动态内存的申请与释放是否配对?(防止内存泄漏)</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">是否有效地处理了“内存耗尽”问题?</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">是否修改“指向常量的指针”的内容?</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="38">重要</td> <td class="xl72" width="620">是否出现野指针?例如(1)指针变量没有被初始化;(2)用free或delete释放了内存之后,忘记将指针设置为NULL。</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">是否将malloc/free 和 new/delete 混淆使用?</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">malloc语句是否正确无误?例如字节数是否正确?类型转换是否正 确?</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl80" height="19">重要</td> <td class="xl72" width="620">在创建与释放动态对象数组时,new/delete的语句是否正确无误?</td> <td class="xl92" colspan="2">无 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td>
</tr><tr><td class="xl86" colspan="4" height="19">类的构造函数、析构函数和赋值函数</td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否违背编程规范而让C++ 编译器自动为类产生四个缺省的函数:</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)缺省的无参数构造函数;</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)缺省的拷贝构造函数;</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)缺省的析构函数;</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(4)缺省的赋值函数。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">构造函数中是否遗漏了某些初始化工作?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否正确地使用构造函数的初始化表?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">析构函数中是否遗漏了某些清除工作?</td> <td class="xl81" colspan="2">析构函数 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">是否错写、错用了拷贝构造函数和赋值函数?</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">赋值函数一般分四个步骤:</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)检查自赋值;</td> <td class="xl81" colspan="2">没有检查自赋值 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)释放原有内存资源;</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)分配新的内存资源,并复制内容;</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(4)返回 *this。是否遗漏了重要步骤? </td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">是否正确地编写了派生类的构造函数、析构函数、赋值函数?</td> <td class="xl81" colspan="2">无派生类的构造函数、析构函数、赋值函数 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">注意事项:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)派生类不可能继承基类的构造函数、析构函数、赋值函数。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)派生类的构造函数应在其初始化表里调用基类的构造函数。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)基类与派生类的析构函数应该为虚(即加virtual关键字)。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(4)在编写派生类的赋值函数时,注意不要忘记对基类的数据成员重新赋值</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl74" height="19"> </td> <td class="xl72" width="620"> </td> <td class="xl81" colspan="2"> </td>
</tr><tr><td class="xl86" colspan="4" height="19">其它常见问题 </td> </tr><tr><td class="xl70" height="19">重要性 </td> <td class="xl77" width="620">审查项</td> <td class="xl89" colspan="2">结论</td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">数据类型问题:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)变量的数据类型有错误吗?</td> <td class="xl81" colspan="2">变量的数据类型没有错误 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)存在不同数据类型的赋值吗?</td> <td class="xl81" colspan="2">不存在不同数据类型的赋值 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)存在不同数据类型的比较吗?</td> <td class="xl81" colspan="2">不存在不同数据类型的比较 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">变量值问题:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)变量的初始化或缺省值有错误吗?</td> <td class="xl81" colspan="2">变量的初始化或缺省值没有错误 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)变量发生上溢或下溢吗?</td> <td class="xl81" colspan="2">变量没有发生上溢或下溢 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)变量的精度够吗? </td> <td class="xl81" colspan="2">变量精度足够 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">逻辑判断问题:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)由于精度原因导致比较无效吗?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)表达式中的优先级有误吗?</td> <td class="xl81" colspan="2">表达式中优先级无误 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)逻辑判断结果颠倒吗? </td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">循环问题:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)循环终止条件不正确吗?</td> <td class="xl81" colspan="2">循环终止条件正确 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)无法正常终止(死循环)吗?</td> <td class="xl81" colspan="2">不存在 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(3)错误地修改循环变量吗?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(4)存在误差累积吗? </td> <td class="xl81" colspan="2">没有误差的累积 </td> </tr><tr><td class="xl71" height="19">重要</td> <td class="xl72" width="620">错误处理问题:</td> <td class="xl81" colspan="2"> </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(1)忘记进行错误处理吗?</td> <td class="xl81" colspan="2">没有忘记进行错误处理 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(2)错误处理程序块一直没有机会被运行?</td> <td class="xl81" colspan="2">否 </td> </tr><tr><td class="xl71" height="38"> </td> <td class="xl72" width="620">(3)错误处理程序块本身就有毛病吗?如报告的错误与实际错误不一致,处理方式不正确等等。</td> <td class="xl81" colspan="2">无 </td> </tr><tr><td class="xl71" height="19"> </td> <td class="xl72" width="620">(4)错误处理程序块是“马后炮”吗?如在被它被调用之前软件已经出错。</td> <td class="xl81" colspan="2">无 </td>
</tr></tbody></table> 评价 --
<font face="宋体"> 通过结合代码审查表对张天翊同学的代码进行审查,我发现了不少闪光点以及不足的地方。此项目虽然并不复杂,但是也可以看出其编码是有一定功底的,代码思路清晰,调用过程简介明了,并且较为符合PEP-8编码规范。 该软件是实现了计算机图形学中的构造直线算法,具体由中点画线法、dda算法和BresenHam算法。分别使用三个模块来实现,通过传入两个点的坐标,模块会返回一个以元组为元素的列表,表示需要被“点亮”的点。 不足的地方:
- 代码中没有版本以及版权申明。
- 部分语句过于冗余。
- 代码注释较少。
- 静态变量、全局变量、类的成员变量没有添加前缀。
- 模块中入口参数没有进行非法检查。
值得学习的地方:
- 头文件的引用符合python规范,先是系统文件,后是自定义库。
- 程序空行得体,符合PEP-8编码规范。
- Switch语句中,一定要编写default语句。
- 函数中参数的参数书写完整。
- 使用for循环进行遍历,可以大大减少死循环发生的可能性。
样例点评: 这里选取了dda算法模块,模块的入口参数为四个数字,分别表示了两个坐标值,
- 对于参数检查这一块,只是用了强制类型转化进行了简单的处理,但是效果并不是很好,如果传入的参数为字符类型,那么就很麻烦了。
- 对于直线段的绘制,这里首先进行了简单的筛选,将斜率为0以及斜率不存在的点进行了特殊操作,在这里选择点的for函数中,min和max两个函数使得代码段虽然很简洁,但是没有考虑到会执行很多次,带来很大的开销。
- 注释太少,尤其是处理一般情况时,倘若不添加注释,很难看清在做什么。
def dda(x1=5, y1=12, x2=0, y2=0):
points = []
x1 = int(x1); y1 = int(y1)
x2 = int(x2); y2 = int(y2)
print('x', 'y')
print(x1, y1)
points.append((x1, y1))
if x1 == 0 and x2 == 0 :
for i in range(min(y1, y2), max(y1, y2) + 1, 1):
print(0, i)
points.append((0, i))
elif y1 == 0 and y2 == 0:
for i in range(min(x1, x2), max(x1, x2) + 1, 1):
print(i, 0)
points.append((i, 0))
else:
dx = x2 - x1; dy = y2 - y1
x = x1; y = y1
ep = max(abs(dx), abs(dy))
xIn = dx / ep; yIn = dy / ep
for i in range(0, ep + 1, 1):
print(int(x + 0.5), int(y + 0.5))
points.append((int(x + 0.5), int(y + 0.5)))
x += xIn
y += yIn
return points
通过此次代码审查的过程,我学习到了代码审查表中的一些要求,并且其中一些要求我发现我以前并没有做到,其实,以前根本没有发现有代码审查表这个东西。虽然这次使用的是C++的代码审查表,而实际中项目的编写使用是Python语言,但是,语言中的核心内容还是很相似的。</font>
参考资料##
来源:oschina
链接:https://my.oschina.net/u/4305544/blog/3563637