个人博客作业2

一. 是否需要有代码规范

  对于是否需要有代码规范,请考虑下列论点并反驳/支持:

     1.这些规范都是官僚制度下产生的浪费大家的编程时间、影响人们开发效率, 浪费时间的东西。

    反驳:代码规范体现友好性,就像语言、货币全国通行,方便我们使用和交流

     2.我是个艺术家,手艺人,我有自己的规范和原则。

    反驳:程序员不同,算法思路不同,最后写出来的程序各有不同,这是必然的,在尊重这样的多样性的前提下,就更该规范代码以使别人更快理解接受你的思路想法,不然在千奇百怪的代码中再用上千奇百怪的规则,实在难以让人吃得消,可维护性可见一斑

     3.规范不能强求一律,应该允许很多例外。

    支持:需要有规范,但是不能有一个绝对的规范,否则当新的语言新的类型诞生的时候其发展可能会受到阻碍

     4.我擅长制定编码规范,你们听我的就好了。

    反驳:如果需要制定编码规范应该民主制定,至少得满足大多数人的需求和接受范围

二. 代码复审

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?

 尽可能的模块化,单看类名就能知道这部分的功能了。

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?

 输出结果的格式正确

Are invalid parameter values handled?

 输入范围为10000时,越界未处理异常

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?

 没有设计测试代码

Are arrays checked for ‘out-of-bound’ errors?

 没有进行数组越界检查

Could any test code be replaced with the use of an existing API?

 没有设计测试代码

posted @ 2015-09-29 20:55  潘礼鹏  阅读(198)  评论(2编辑  收藏  举报