分享
 
 
 

C# Code Review Checklist

王朝c#·作者佚名  2006-01-09
窄屏简体版  字體: |||超大  

Ted GraHam 提到了39 条 CheckList, 我觉得还是总结的挺全面.

Are exceptions used to indicate error rather than returning status or error codes?

使用异常来只是错误而不是使用状态或者错误代码值

Are all classes and public methods commented with .NET style comments?? Note that comments should discuss the "what" of public methods.? Discussion of "how" should be in blocks or in-line with the code in question.

所有类以及 public 方法 都使用.NET 样式的注释, 即 /// summary 格式. 注意 Summary 中说明代码有那些功能,而不是这个功能如何实现的. 可以在 Remarks 块或者代码中说明.

Are method arguments validated and rejected with an exception if they are invalid?

所有方法的参数的合法性是否做验证, 对非法的参数是否抛出异常?

Are Debug.Asserts used to verify assumptions about the functioning of the code?? Comments like, "j will be positive" should be rewritten as Asserts.?

是否使用 Debug.Asserts 来验证代码中的假设? “ j 应该是正数?“之类的注释应该用 Debug.Asserts 来重写.

Do classes that should not be instantiated have a private constructor?

不需要实例化的类有 私有构造函数吗?

Are classes declared as value types only infrequently used as method parameters, returned from methods or stored in Collections?

值类型的类用于参数,方法返回值以及存放在集合中?

Are classes, methods and events?that are specific to an assembly marked as internal?

Assembly 特有的类,方法,事件的访问修饰符是否已经标记为 Internal ?

Are singletons that may be accessed by multiple threads instantiated correctly?? See the Enterprise Solution Patterns book, p. 263.

多线程同时访问的单件对象是否正确的初始化?

Are methods that must be overriden by derived classes marked as abstract?

必须被衍生类重写的方法申明为 Abstract 了吗?

Are classes that should not be overriden marked as sealed?

不能重写的类是否标记为 Sealed?

Is "as" used for possibly incorrect downcasts??

可能失败的转换是否使用了 AS 运算符?

Do classes override ToString?instead of defining a Dump method for outputting the object's state?

输出对象的状态的时候应该重写 ToString 方法而不是加一个类似 Dump 之类的方法.

Are log messages sent to the logging component instead of Console?

所有log 的消息都有 log 组建处理,而不是仅仅输出到 控制台.

Are finally blocks used for code that must execute following a try??

finnally 代码块用于try 后必须执行的代码

Is foreach used in preference to the for(int i...) construct?

尽可能的采用 foreach 而不是 for(int i...)

Are properties used instead of implementing getter and setter methods?

是否属性没有实现getter 和 setter 方法

Are readonly variables used in preference to?properties without setters?

只读的属性应该没有 setter 方法

Is the override keyword used on all methods that are overriden by derived classes?

衍生类重写的方法是否都使用了 override 关键字

Are interface classes used in preference to abstract classes?

正确的使用interface 和抽象类.

Is code written against an interface rather than an implementing class?

接口实现和抽象类继承

Do all objects that represent "real-world" or expensive resources implement the IDisposable pattern?

操作系统资源的类是否实现了 IDisposable 接口?

Are all objects that implement IDisposable instantiated in a using block?

是否所有实现IDisposable 的类初始化的时候使用了 Using 语句?

Is the lock keyword used in preference to the Monitor.Enter?construct?

使用lock 语句而不是 monitor.enter

Are threads awakened from wait states by events or the Pulse construct, rather than "active" waiting such as Sleep()?

线程使用事件或者pulse 唤醒, 而不是使用 sleep 主动的唤醒.

If equals is overridden, is it done correctly?? The rules for overriding equals are complex, see Richter p153-160 for details.

是否正确的重写了 equals

If == and != are overridden, so they redirect to Equals?

== 和 != 操作符号被重写

Do all objects that?override Equals also provide an overloaded version of GetHashCode that?provides the same semantics as Equals?? Note that overrides to GetHashCode should?take advantage of the object's member variables, and must?return an unchanging hash code.

Equals GethashCode 的重写问题

Do all exception classes?have a constructor that takes a string and and another constructor that takes a string and an exception?

异常类的构造问题

Do all exception classes derive from the base Matrix exceptions and fit correctly into the exception hierarchy?

自定义异常类的继承层次问题

Are all classes that will be marshaled or remoted marked with the Serializable attribute?

所有被 Marshal 或者远程处理的对象有序列化标志

Do all classes marked with the?Serializable attribute have a default constructor?? This includes Exception and?EventArgs?classes.

所有标记有 Serializable 属性的类是否有默认的构造函数, 包括常见的 Exception 和 EventArgs 类.

Do all classes that explicitly implement ISerializable provide both the required GetObjectData and the implied constructor that takes a SerializationInfo?and a?StreamingContext?

实现 Iserializable 接口的类是否显式的实现 GetObjectData 和 隐式的构造函数,例如 Serializaioninfo 和 StreamingContext 作为参数

When doing floating point calculations,?are all constants doubles rather than integers?

做浮点运算的时候,所有的常量都是double 类型而不是整数

Do all delegates have a void return type and avoid using output or ref parameters?

委托是否都有 void 返回值,避免使用 out 或者 ref 类型的参数

Do?all delegates send the sender (publisher) as the first argument?? This allows the subscriber to tell which publisher fired the event.?

所有的委托又有 sender 对象作为第一个参数

Are all members of derived EventArg classes read-only?? This prevents one subscriber from modifying the EventArgs, which would affect the other subscribers.

从 EventArg 继承的类是否是只读的, 只读的参数可以避免一个订阅者对参数的修改影响其他的参数订阅者

Are delegates published as events?? This prevents the subscribers from firing the event, see Lowy, p. 102?for details.

所有的委托发布事件?

Is common setup and teardown nUnit code isolated in?Setup and Teardown methods that are marked with the appropriate attribute?

单元测试的时候, 常见的驱动代码和测试代码分开.

Do negative nUnit tests use the ExpectedException attribute to indicate that an exception must be thrown?

使用 ExpectedExcetpion 来指示异常必须抛出?

20040810 Montaque

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
2023年上半年GDP全球前十五强
 百态   2023-10-24
美众议院议长启动对拜登的弹劾调查
 百态   2023-09-13
上海、济南、武汉等多地出现不明坠落物
 探索   2023-09-06
印度或要将国名改为“巴拉特”
 百态   2023-09-06
男子为女友送行,买票不登机被捕
 百态   2023-08-20
手机地震预警功能怎么开?
 干货   2023-08-06
女子4年卖2套房花700多万做美容:不但没变美脸,面部还出现变形
 百态   2023-08-04
住户一楼被水淹 还冲来8头猪
 百态   2023-07-31
女子体内爬出大量瓜子状活虫
 百态   2023-07-25
地球连续35年收到神秘规律性信号,网友:不要回答!
 探索   2023-07-21
全球镓价格本周大涨27%
 探索   2023-07-09
钱都流向了那些不缺钱的人,苦都留给了能吃苦的人
 探索   2023-07-02
倩女手游刀客魅者强控制(强混乱强眩晕强睡眠)和对应控制抗性的关系
 百态   2020-08-20
美国5月9日最新疫情:美国确诊人数突破131万
 百态   2020-05-09
荷兰政府宣布将集体辞职
 干货   2020-04-30
倩女幽魂手游师徒任务情义春秋猜成语答案逍遥观:鹏程万里
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案神机营:射石饮羽
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案昆仑山:拔刀相助
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案天工阁:鬼斧神工
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案丝路古道:单枪匹马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:与虎谋皮
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:李代桃僵
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案镇郊荒野:指鹿为马
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:小鸟依人
 干货   2019-11-12
倩女幽魂手游师徒任务情义春秋猜成语答案金陵:千金买邻
 干货   2019-11-12
 
推荐阅读
 
 
 
>>返回首頁<<
 
靜靜地坐在廢墟上,四周的荒凉一望無際,忽然覺得,淒涼也很美
© 2005- 王朝網路 版權所有