zoukankan      html  css  js  c++  java
  • 个人博客作业2

    关于代码规范的讨论


     

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

    1. 这些规范都是官僚制度下产生的浪费大家的编程时间、影响人们开发效率, 浪费时间的东西。
    2. 我是个艺术家,手艺人,我有自己的规范和原则。
    3. 规范不能强求一律,应该允许很多例外。
    4. 我擅长制定编码规范,你们听我的就好了。

    对于论点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?

      使用c++编写,代码较为易懂,少有无意义的短变量名,类的设置合理。有注释说明了程序思路。

    • 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?

      没有全局变量,但是类属性均为public

    • 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?

      没有测试

     

     

  • 相关阅读:
    【leetcode】修剪二叉搜索树
    053-621
    053-620
    053-619
    053-618
    053-617
    053-616
    053-615
    053-614
    053-613
  • 原文地址:https://www.cnblogs.com/dtblog/p/4846523.html
Copyright © 2011-2022 走看看