一. 是否须要有代码规范程序员
对因而否须要有代码规范,请考虑下列论点并反驳/支持:算法
1.这些规范都是官僚制度下产生的浪费你们的编程时间、影响人们开发效率, 浪费时间的东西。编程
反驳:代码规范体现友好性,就像语言、货币全国通行,方便咱们使用和交流数组
2.我是个艺术家,手艺人,我有本身的规范和原则。数据结构
反驳:程序员不一样,算法思路不一样,最后写出来的程序各有不一样,这是必然的,在尊重这样的多样性的前提下,就更该规范代码以使别人更快理解接受你的思路想法,否则在千奇百怪的代码中再用上千奇百怪的规则,实在难以让人吃得消,可维护性可见一斑ide
3.规范不能强求一概,应该容许不少例外。模块化
支持:须要有规范,可是不能有一个绝对的规范,不然当新的语言新的类型诞生的时候其发展可能会受到阻碍函数
4.我擅长制定编码规范,大家听个人就行了。oop
反驳:若是须要制定编码规范应该民主制定,至少得知足大多数人的需求和接受范围测试
二. 代码复审
General |
|
Does the code work? Does it perform its intended function, the logic is correct etc. |
代码并无彻底完善,生成功能和计算功能实现可是仍有缺陷,检验和查重功能未开发。 |
Is all the code easily understood? |
代码风格清晰,虽然并非十分规范可是容易理解,关键地方有充分的注释 |
Does it conform to your agreed coding conventions? These will usually cover location of braces, variable and function names, line length, indentations, formatting, and comments. |
十分规范,大括号另起一行以及留空格习惯使代码看起来格式赏心悦目,变量名多而准确 |
Is there any redundant or duplicate code? |
有一些地方能够简化合并一下 |
Is the code as modular as possible? |
采用C编写,并无采用面相对象程序设计,并无模块化,可是并不十分影响理解 |
Can any global variables be replaced? |
全局变量少,一些用来传递的参数能够设置为全局的 |
Is there any commented out code? |
有被注释掉的代码 |
Do loops have a set length and correct termination conditions? |
是的 |
Can any of the code be replaced with library functions? |
能用到库函数的都用到了 |
Can any logging or debugging code be removed? |
有的被注释到了 |
Security |
|
Are all data inputs checked (for the correct type, length, format, and range) and encoded? |
没有 |
Where third-party utilities are used, are returning errors being caught? |
没有 |
Are output values checked and encoded? |
没有,存在生成的真分数分母为0的状况没有处理 |
Are invalid parameter values handled? |
没有 |
Documentation |
|
Do comments exist and describe the intent of the code? |
没有写文档 |
Are all functions commented? |
没有写文档 |
Is any unusual behavior or edge-case handling described? |
没有写文档 |
Is the use and function of third-party libraries documented? |
没有写文档 |
Are data structures and units of measurement explained? |
没有写文档 |
Is there any incomplete code? If so, should it be removed or flagged with a suitable marker like ‘TODO’? |
没有写文档 |
Testing |
|
Is the code testable? i.e. don’t add too many or hide dependencies, unable to initialize objects, test frameworks can use methods etc. |
程序并不能经得起测试 |
Do tests exist and are they comprehensive? i.e. has at least your agreed on code coverage. |
程序中没有包含测试用例 |
Do unit tests actually test that the code is performing the intended functionality? |
程序中没有包含unit tests,须要人工测试 |
Are arrays checked for ‘out-of-bound’ errors? |
数据结构多使用数组,所有设定在数组范围内并无出现out-of-bound |
Could any test code be replaced with the use of an existing API? |
程序中没有包含test code |