Q:是否需要有代码规范
Q:代码复审
| 
 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?  | 
 个别一些地方比如ifelse哪里换成case也许会简化一些  | 
| 
 Is the code as modular as possible?  | 
 已经很模块化了,但是program这里的运算还是可以也做成函数调用的。  | 
| 
 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?  | 
 在输入时没有catch exception  | 
| 
 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’?  | 
 answersfile计算未完成,没考虑负数  | 
| 
 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?  | 
 数据结构多使用Queue,使用中没有遇到out-of-bound问题  | 
| 
 Could any test code be replaced with the use of an existing API?  | 
 程序中没有包含test code  | 
1.代码可以正常的从文件中读入和输出到文件中数据。一共生成了100个练习表达式和100个答案。并且答案都是正确的。而且程序和函数的逻辑也是对的。但是有一个问题就是,输出的结果都是10个一样的答案和表达式,并且每次重新生成工程也都是一样的结果。所以真对于这个代码
public Create(int n, int r){
            Random random = new Random();
      quantity = n;
      maxrange = r;
      signNum = random.Next(0,4);
      sign.Add(‘+‘);
      sign.Add(‘-‘);
      sign.Add(‘*‘);
      sign.Add(‘/‘);
     }
可以看出生产随机数的代码本身没有问题,用Random.Next产生随机数。问题的原因是每次都new一个初始化对象时,对象都是使用当前时间生成一个随机数的种子,这就意味着在循环时可能得到相同种子的Random实例。
解决办法可以如下:
private static readonly Random random = new Random();
private static readonly object syncLock = new object();
public static int RandomNumber(int min, int max)
{
    lock(syncLock) { // synchronize
        return random.Next(min, max);
    }
}
private static readonly ThreadLocal<Random> appRandom = new ThreadLocal<Random>(() => new Random());
public static int GetRandomNumber()
{
    return appRandom.Value.Next();
}
既然用了lock就有可能影响到性能。可以把随机数实例放到ThreadLocal中来保证每个线程一个Randonm实例。
2.所有的代码都比较容易理解。
3.比较符合我的代码编码约定,尤其是写完了大括号之后有换行和缩进,也不存在多行代码写在一行的情况。整个代码命名了很多类,起的名字都直观易懂,将整个程序非常好的模块化,对象化的完成。
原文:http://www.cnblogs.com/hshang/p/4847638.html