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.

Saturday, February 9, 2013

Online File Extension Identifier

Today, I tried to open a file which I received through email from some company. First I downloaded the file, after that tried to open it but it wasn't opening as the file does not have any extension.

I tried to open it from 'Open With' option and checked by selecting word, excel, rar, zip, etc but no luck. Then I right clicked the file and checked the details, unfortunately, no details available and no information on extension available. Finally, I started googling by typing this phrase: 'if file type is file how to open'. In the first page results I found an interested link: http://mark0.net/onlinetrid.aspx I opened this site and just given my file local path and clicked on Analyze button and hurray within a second in the below grid I got the file information. The extension was PDF...

What an experience it was...It was very helpful because I didn't had much time to contact the sender and enquire about the file type through email :)

Tuesday, November 20, 2012

C#er : IMage: Model-View-ViewModel (MVVM) Explained

C#er : IMage: Model-View-ViewModel (MVVM) Explained: The purpose of this post is to provide an introduction to the Model-View-ViewModel (MVVM) pattern. While I've participated in lots of discus...




Sunday, November 11, 2012

One thing which initiated my interest in Computer Programming is Mathematics.



One thing which initiated my interest in Computer Programming is Mathematics.
I still remember my schooling days when I was in 8th standard and was not so good at Maths subject. One of my friend (Ajaz - plz don't read it as Ajax - hehe) from our locality, insisted me to join a private Maths tutor classes to improve my Maths skills. In the very second month learning I started grasping the subject in a very good pace and as well as my interest towards it increased a lot. Finally in less than a year I became fond of Maths and it showed the result in my Score Report cards. I was scoring around 80%.
Now I started practising a lot to score 100% when I was in 10th standard but managed to get only 94%. My interest and practice increased even more and finally it paid me and God helped me to score 100% in 10+2 Maths subject.
Once I finished my Intermediate (10+2) I started correlating my skills with the fields to choose from, for my Graduation and it was Mathematics magic that realized me that I'm meant for Computer Programming world.
And those days (year 2001) BCA was one of the booming Graduation choice for Computers. Hence I decided to join BCA and I had to write an BCA Entrance exam (I scored 522 rank). Finally joined OUPG College for BCA (It was top college in a list of 3 given to me in Counselling).

Saturday, October 13, 2012

Steps: Check-in/Check-Out Mechanism for TFS - To avoid Build errors and improve Productivity



You all may be already aware of TFS and its usage to effectively work as a Team on a Team Project but I thought to reassemble some of the important points/steps to ensure good Productivity (by avoiding Build errors as much as possible).

So please read the below points and also add your feedback by adding your comments to make this more informative (This would really help especially if 'Multiple Checkout' option is Enabled):

1.      Always make it a practice to Get the latest version of the Project daily morning before you start your work.
2.      Build/Rebuild your Solution to ensure that there are no build errors.
                  -->If you get any build errors, check what are those. Suppose if they are simple to resolve like 'Broken Reference' errors or any other                              simple errors please take initiative and resolve them. If you notice that they belong to some other Team member's task please                                  intimate him/her so that they could fix it.
3.      Check out the file(s), which are relevant to your task and start working. Once you are done with your work, verify it by building the project. And          if you don't find any build errors; run the project and test your page whether it is working fine. If its fine, check in your files. If you find any build          errors or runtime issues then resolve them and then check in.
                  --> It's always a good Practice to divide a big Task in smaller tasks and on each sub task's success you can check in your work. For example UI design, populating dropdowns, placing validations, saving form data, displaying grid data, etc can all be treated as individual sub tasks for a particular page functionality. This will ensure that you will not have any pending check ins at the end of the day and also it keeps things easy. If a sub task is taking a longer time and if you want to continue it the next day, you can comment your partial written code and check in the file. The next time you start work you can checkout, uncomment your code and start working. This practice will minimize the usual conflicts we get when we are working under 'Multiple checkout' option enabled and also it will not have any impact if TFS connectivity issue occurs.
4.      Sometimes when we take latest version from TFS we get some conflicts in some files, check these conflicts carefully and if the files don't belong to you, you can straightaway choose the option 'Resolve Conflicts'. Then VS/TFS takes care to automatically resolve conflicts for you. And if a file belongs to you on which you recently worked on then most of the times you have to choose 'Auto Merge' option so that your changes and the last guy who has checked in recently, his changes, would be automatically merged and saved to TFS. And still if you feel you have to cross verify the changes, you can trace them in 'Merge Tool' option and then merge it.
5.      Till now the check in and check out process what we discuss is for the existing files in our project but there is a slight difference in case of adding a new file, renaming a file, deleting a file. As TFS and your project are already have metadata reference/info of your existing files, hence it only checkouts the file when you start making any changes or if you explicitly check out it but it will not checkout your project. 
But in case of adding a new file, renaming a file, or deleting a file the TFS and project will not have this reference in .csproj file and source control .vss file or it might need to update the metadata info of that file; hence it checks out the Project as well whenever this kind of operation happens on a particular file. If you are familiar with File system and file handlers it would be much easy to understand this TFS behavior. Now you need as usual build and run your project, verify and then check in the pending items (file plus project).
This practice as well minimizes the possibility of getting conflicts and therefore makes things much simpler and in our control.


Finally our objective should be to simplify our work and avoid confusions and also make sure to avoid error-prone check ins. (Note that a small mistake from an incorrect check in could create lot of build errors for other team members hence affecting their productivity).


Your inputs, clarifications, and feedback in this regard would be highly appreciable.

Thanks.