Saturday, June 8, 2013

Top 10 C# Guidelines and Code reviews checklist for Developers

Introduction

This is a General Code Review checklist and guidelines for C# Developers, which will be served as a reference point while development. This is to ensure that most of the General coding guidelines have been taken care of, while coding. Especially, it will be very helpful for entry-level and less experienced developers (0 to 3 years exp.) to refer this checklist until it becomes a habitual practice for them.


Complete checklist reference

This is only Top 10 checklist items. If you are interested to have a look at the complete list (around 40 items) please visit here:     http://www.codeproject.com/Articles/593751/Code-Review-Checklist-and-Guidelines-for-Csharp-De

Checklist

1. Make sure that there shouldn't be any project warnings.

2. It will be much better if Code Analysis is performed on a project (with all Microsoft Rules enabled) and then remove the warnings.

3. All unused usings need to be removed. Code cleanup for unnecessary code is always a good practice.


4. 'null' check need to be performed wherever applicable to avoid the Null Reference Exception at runtime.

5. Naming conventions to be followed always. Generally for variables/parameters follow Camel casing and for method names and class names follow Pascal casing.


6. Make sure that you are aware of SOLID principles.

Definition from Wikipedia: In computer programming, SOLID (Single responsibility, Open-closed, Liskov substitution, Interface segregation and Dependency inversion) is a mnemonic acronym introduced by Michael Feathers for the "first five principles" identified by Robert C. Martin[1][2] in the early 2000s[3] that stands for five basic principles of object-oriented programming and design. The principles when applied together intend to make it more likely that a programmer will create a system that is easy to maintain and extend over time.[3] The principles of SOLID are guidelines that can be applied while working on software to remove code smells by causing the programmer to refactor the software's source code until it is both legible and extensible. It is typically used with test-driven development, and is part of an overall strategy of agile and adaptive programming.


7. Code Reusability: Extract a method if same piece of code is being used more than once or you expect it to be used in future. Make some generic methods for repetitive task and put them in a related class so that other developers start using them once you intimate them. Develop user controls for common functionality so that they can be reused across the project.



8. Code Consistency: Let's say that an Int32 type is coded as int and String type is coded as string then they should be coded in that same fashion across the application. But not like sometimes int and sometimes as Int32.

9. Code Readability: Should be maintained so that other developers understand your code easily.


10. Disposing of Unmanaged Resources like File I/O, Network resources, etc. They have to be disposed of once their usage is completed. Use usings block for unmanaged code if you want to automatically handle the disposing of objects once they are out of scope.


 

Conclusion


I welcome feedbacks, queries, and suggestions from the readers so that I can improve it further and developers should get some benefit out of it. My aim is to gradually make it a complete Code review guidelines especially for C# developers and in next version I'm planning to add supporting code examples and screenshots for much better understanding purpose.
Disclaimer: This document does not guarantee that all the mentioned guidelines and practices are applicable as of today. Therefore it is always recommended to check yourself MSDN, discuss with experts and check other portals for the current and modified guidelines and practices. Also, note that some of the provided reference links might not work.

1 comment:

  1. Code review checklist is very helpful to improve quality of codes. Good points made in this blog on code review checklist. Thanks for sharing.

    ReplyDelete