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 来指示异常必须抛出?
新闻热点
疑难解答