6 Ways to use Code Comments effectively


When you are learning to code it almost always follows the path of spaghetti-code. But, there is one magic bean you can use in your code which will make your life easier when you look back at your own code (or someone elses') 10 years later. 

"// Comments"
I haven't been coding for 10+ years but all these years that I've looked at or got a chance to work on someone else's code, proper meaningful comments made my job way more productive than any other tool that I've come across. Because, good comments tell us WHY the code is that way. While the code itself tells me what it is doing.

Following are sort of best practices/guidelines for good comments. If your code is self explanatory, by all means, forget about commenting. But, if there is at least one shady magical piece of work that your code is doing, you might want to think about adding proper comments on them. Please note that this is by no means a full list of guidelines but rather a short and sweet version. 

  1. Code should be self-explanatory
  2. Tell us WHY, explain the logic/reasoning
  3. Comments must be meaningful
  4. Do not add noise
  5. Do not comment on simple stuff
  6. Be mindful when using comment generators  

Popular posts from this blog

Print a sales receipt using a thermal printer with C# for POS Application

Automatic redirect upon session timeout using ASP.NET MVC and Javascript

Could not create SSL/TLS secure channel - Fixed