您的位置:首页 > 编程语言

个人博客作业2--代码规范和代码复审

2015-09-29 18:44 260 查看
代码规范:

  代码规范作为coders所遵守的一个默认的准则,其存在的意义是十分重要的。

  不以规矩,不能成方圆。如何正确、规范的工作,如何为我们的工作提供依据,并能够高效率的执行,这些都需要正确、行之有效的规范。而代码规范正是保证这一切的基础。它使得不同的人在相互合作的时候能够更加迅速、容易地理解彼此的工作进度与代码信息,为之后的协作提供一个良好的沟通环境。一个人的能力十分有限,所以与他人的沟通协作不可或缺,这更加彰显出代码规范的重要。

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

  代码规范的产生并不是出于官僚制度,它的产生是符合代码编写需要的,是必然的产物。其目的是提高代码编写的效率,节约工作时间。或许在一个人单独工作的时候,代码规范会消耗部分的时间,但从团队的角度看来,这一点点的时间消耗换来的整个团队开发时间的降低以及开发效率的大大提升。如果没有这个规范,那么团队成员彼此都需要花费大量的时间去理解对方的代码习惯,对于几十人甚至上百人的团队而言,这种事情简直荒唐可笑,更不可能写出一个好的产品。

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

  这句话就更逗了...你明明就是个码代码的,还自称艺术家,难道码代码也算是行为艺术吗...说自己是手艺人倒是勉强可以接受,毕竟是靠手码出的代码。有自己的规范和原则,没问题,自娱自乐足矣。但是如果是和别人一起工作,这种想法还是不要有了。只顾着自己写代码写爽了,却不顾别人痛苦地分析你的代码究竟是什么意思,这么自私的行为就不怕遭到同事们的群殴吗0.0

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

  例外当然可以存在,不过如果出现很多例外,那就不行了。对于一个规范而言,有个别的例外很正常,毕竟每个人都有自己的特点,不可能完全一模一样。但如果例外过多,那么规范的权威性就受到了巨大的挑战。每个人都出现很多的例外,那么这个所谓的规范也只不过名存实亡,没有任何用处了。

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

  我觉得可以让持第四条观点的人和持第二条观点的人去谈一谈,看看这两个中二少年会不会打一架。毕竟这两条观点都实在是太以自我为中心了。在团队的工作中,每个人都是不可或缺的一部分,但这并不是说别人就必须随着自己的意愿。规范的制定应该是根据团队里所有人的状况以及任务需求来决定的,而不是由一个人全权负责。

代码复审:

这是我对我的结对的小伙伴的代码的复审0.0

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.

无论是变量名称的设置,还是代码风格都很好,我应该好好学习学习,我平时真是太随意了0.0

Is there any redundant or duplicate code?

formula_generate 函数包含的功能太多了,划分的更细致一点,可能会简化一部分的功能和代码。

Is the code as modular as possible?

Main函数只有寥寥几行,将其他部分再封装一下应该就实现模块化了。

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?

输入不合法的参数会进行提示,并结束程序

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?

没有设计测试代码

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: