I recently read this long discussion on slashdot on commenting the code.There were people saying 'dont comment your code ,only then people willcome back and ask you and you become important'.
Shocking???Yes but there are a frustrated & insecure few who feel the same.But looking at the larger issue, I think everyone is for commenting.But the big questions are
1. How to comment(Format)
2. How much to comment.
The first point on the format to comment is pretty much standarised.It is either defined at the project level or the technology level.There are doc toolsand ide's that help in this.
The second question on how much to comments is the big complex one. Acode with excess comment by no means becomes a 'well commented code'. Toomany comments is annoying and distracts you from thinking. In large and long projects, the comments very often dont match what the code does. Yes this is true.Many times the code gets changed but not the comments.So what is the useof the comments??Ok ,the comments dont decide what the program does.It is the code that tells the truth.The comments just help you to get 'in flow'.Thats what my mentor used to tell me.'Remember,You Are Writing Code For People,NOT Computers.You write code that is self documented.'
Self Documented??? That is giving the variable and method proper names which by themselves describe what they are doing. Writing the code in the least complicated way.Hence think before you code. Its easier said than done.Very often you need to fix problems before a deadline and hence becomes very difficult to do all this.
One more thing I want to add is commenting small things. I mean in a thousandlines of code ,someone adds a line to check for null,and they comment it
// Checked for Null by Name(id) Date
if(loValue!=NULL) //Check if loValue is not Null Do something...
I mean if people start adding their names for all these triffle things the sizeof the file starts becoming ugly.I know its nice to have your name all around the code.But then there is a limit.Unless the code is getting changed in flow or it happens to be someone elses code,I think all minor changes can go without this.
But again the question as to what is major and minor is something to think about.Finally I think the code you write should be legible enough so that its easy to maintain.I think every coder takes pride in it.
Subscribe to:
Post Comments (Atom)
2 comments:
I honestly agree with you.
This is a famous way of keeping track of changes in administrative scripts, receipe files and configuration files, in which it is extremely important to know who did what.
But following a similar kind of approach in the source code of an application is not called for as, the CVS already takes care of storing who did what!
Post a Comment