A few Comments on Comments
A few Comments on Comments
/*
********************************************************
You are not the owner of the code that you write. The owner is always the organization who you are working for, or the customer who you write the code for. So, please write proper Comments with your well-designed and beautifully-working source code, so that it helps you and other developers during and after the development cycle.
********************************************************
*/
Let us talk something specific than general suggestions.
What doesΒ properΒ mean here? Is it proper style and syntax?Β Is it writing in proper place?Β Or Is it writing proper text?
So,Β how about aΒ few comments on Comments:
//
// Donβt hesitate writing a long Comment when it is necessary.
// Donβt sacrificeΒ Comments for a beautifully-looking code.
//Β
// βPurposeβ of a Comment overrulesΒ βBeautyβ of code.Β
//
//Β Donβt just explain the WHAT part but explain the WHY part.
// Most of the timesΒ WHAT is more obvious with proper coding standards.
//
Example:
// Sleeps for 5000 ms Thread.sleep(5000);
The above doesnβt serve any purpose. Rather, something similar to the following comment would serve the purpose right.
// (What) Allow time for the input processing. // (Why) From the testing performed, it usually takes around 2000-3000 ms in normal // workload scenarios. So, using a 5000 ms delay to be on a safer side, considering // significantly higher workloads and at the same time not slowing down theΒ processing time. // (Why for future) When we support xyz interface in future, we need to revisit this interval. // We need more time delay to be allowed on xyz interface. // So, the performance with this interface might be a bit compromised. //β¦ //β¦ Thread.sleep(5000);
//
// Donβt add Comments which are very obvious.
//
// Comments and Coding Standards are Complements but NOT
// Replacements toΒ one another.
//
Example:
// Copy all elements, field by field, from source to target. for(β¦) src = getNextSrcElement();
target = geNextTargetElement();
// copy src name to target name
target.name = src.name;
// copy src title to target title
target.title = src.title;
//Allowed bonus is 50% more in target per the following requirement
//β¦.
//β¦.
target.bonusLimit = 1.5 * src.bonusLimit;
β¦
β¦
β¦
//
// Necessary Comments are MUST than GOOD-TO-HAVE. //Β // Working-code is a subject of your Design and Coding skills and it is for your // Compilers and Computers;Β // Explaining-code is a subject ofΒ your Comments and Coding Standards andΒ // it is for us, the Human-beings. //
Fixing an βUndeclared Variableβ error is a MUST situation that your compiler creates for you. Fixing an βUnexplained Codeβ is a MUST situation that you need to create for yourself.
ββββββββββββββββββββββββββββ- I donβt believe poor Comments haveΒ impact on Quality !!! ??? TheyΒ areΒ just plain text.
Β Yes, they may not have immediate or direct impactΒ and thatβs probably why some developers safely put them on the back burner. But in the long run, here are some of theΒ bonus items offered by an βunexplainedβ or βimproperly explainedβ code.
β Removing/Modifying a line of code which shouldnβt have been and thus attracting regressions. β Longer cycles to understand the code as part of code reviews, bug fixing, code extensions etc.. βΒ βββββββββββββββββββββββββββ
So, the inference is:
// Our goal is not βwriting Commentsβ but it is βwriting some useful information, which cannot be conveyed just though the executable code, in the form of Commentsβ.
// Write βNecessary and Sufficientβ Comments maintaining the balance between Readability and Maintainability of the code.
// Once you have written the Comments, read them βfrom the futureβ point of view and βfrom the eyes of the other developersβ to ensure the Comments are serving their purpose right. If you want to understand βwhyβ, try reading your own code (without comments) that you have written a few weeks back.
After thought:
Does your team understand what βproperβ Comments mean?
Does your team understand the role of proper Comments in the long run maintenance of the code?
This blog first appeared inΒ βBeyond your CodeβΒ on 28 Aug, 2012.
<!-- if(wpa2a)wpa2a.script_load(); //--><!-- if(wpa2a.targets)wpa2a.targets.push( title:"",url:""); if('function'===typeof(jQuery))jQuery(document).ready(function($)$('body').on('post-load',function()if(wpa2a.script_ready)wpa2a.init();wpa2a.script_load(););); //-->
https://www.3esofttech.com/a-few-comments-on-comments/
Comments help developers during and after the development cycle.














