第二次个人作业

一、回答问题

1

我不认为按照代码规范写代码能够多用多少时间。而且,在这个讲究团队合作的时代,每个人写的代码都会让别人来看。如果没有代码规范,别人看代码将要多花很多时间,这远远要多于自己节省的时间。我个人的体会,我作为信息安全数论实验的助教,有一少部分学生的代码规范性很差,随意命名,函数没有解释,这极大的增加了我阅读代码的时间,我深受其害。这种规范不是官僚制度下产生的,而是人们在实践中摸索出来的高效方法。如果连代码规范的产生都说不对,又何以批评它呢?

2

艺术家、手艺人自然可以有自己的规范和原则。但是一群艺术家,他们要是人人按照自己的原则来做事,那还怎么创造出优秀的成果。而实际上,很多艺术家在一起,他们也能有合作的成果。这就是因为他们为了大的目标,牺牲了自己小的特别的规范和原则。

3

规范确实不是千篇一律的,肯定也有例外。但是这里的例外指什么呢?它是指每个公司都已一种规范,虽然大同,但也有小异,这就是规范不是千篇一律的。但是不能认为是在一个团体中,团体制定好了规范,却有几个特别的人是例外。这样极大的破坏了规范性,降低了效率。所以这里的例外指的是独立的集体,而不是一个集体中的个人。

4

这句话颇有些自大。擅长指定规范就能够指定规范吗?举一个公司来说,在你去之前,规范就已经产生了,就因为你擅长指定规范,公司就会改规范吗?不会的。同时,如何就说明别人不比你擅长指定规范呢?同时,规范应该考虑到各种情况,应该是由多个人确定的,不应一人确定。

二、代码互审

优点:

1、代码能正常运行,逻辑是正确的,虽然只实现了部分功能,只有生成表达式的功能,没有计算和匹配答案的功能。

2、所有代码容易理解,命名规范,代码和我理解的是一致的。

3、代码模块化,相近的功能写在同一个类中。

不足:

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?

没有处理。

Documentation

没有文档。

Testing

Is the code testable? i.e. dont 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?

没有。

原文地址:https://www.cnblogs.com/jirufeng/p/4847056.html