Why we use comments in C# code

Comments in coding plays a vital role when we work in a team or individual. Now we will get to know why to use comments while coding and how its help us. Now We will discuss about the benefits of comments in C#
Normally, when we were were fresher in IT industry, completing the task given to us by our seniors or deeds which we used to set to do in particular day or duration. So during the phase when we were coding the steps and methods output we and God know, but after some weeks or month that codes only God knows (Many developer have that story). Now when we use to see some of that codes our self don’t know for what purpose we have written unless and until we do debug.
So to overcome this all problem comments comes in picture. Comments is basically use to put the work or operation which the line of code or method is doing.
There are 2 types of comments in C#.We will discuss here about
a) Single line comment(//)
b) Multi Line comment(/*… */)

Why Use Comments

1. Understanding  – Basically when the coder codes for any task the team leader or senior developer does not reviews the whole code line by line, they just want to know that the given task is working or not(as they do not have much time to go through it), so if the coder comments at the lines of codes for which it has written it will be easy to understand that the particular line has logic and the particular line is focus of the particular task.
2. Effects in  Change request – When the change request comes for particular modules or functionality, then comments makes a vital role. Developer should have a practice of commenting the existing code and writing a new code which should have a meaningful comment i.e. why the change request is been done, and what the functionalities will be affected(This i realized when I did coding and after some change request came, and I was speechless because i forgotten the flow, and it took much time to recall it).
3. Helps everybody – Just imagine you are on leave for couple of week and some urgent requirement comes, so it will be very difficult for your team leader or your own colleagues to understand the flow and the modules if the proper comments is not their. so its a good practice to comment in your code snippet.
4. Good Practice – Its always a good practice to place comment in your code for better understanding. Moreover you can find the code easily which you have used for specific purpose. It happens many times with that We have written some code, that similar functionality when We want in other module We can get easily due to proper comment.
Hope you guys will get some points to remember that comments are also important part of coding. We know its little bit difficult to put comments while you are coding as it distracts from the deeds to be done, but after finishing the code snippet we can give time for comments in our code.

Tagged , , . Bookmark the permalink.

Leave a Reply