程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> C語言 >> 關於C語言 >> C# Code Review Checklist

C# Code Review Checklist

編輯:關於C語言
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 來指示異常必須拋出?
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved