02-11-2003
104,
0
Join Date: Aug 2001
Last Activity: 25 October 2010, 3:31 AM EDT
Location: UK
Posts: 104
Thanks Given: 0
Thanked 0 Times in 0 Posts
Whenever I take on new code, whatever the language, I usually find that it has poor commenting and bad indentation.
Many programmers have their own styles it is true, but then again many programmers are untidy and inconsistent.
A good way of learning a new piece of code is to go through it and tidy it up.
By adding comments and correcting indentation you will find you have to think about what the code is doing on a line by line basis.
Although this may seem a trivial or pendantic exercise I have always found it a useful technique in learning some else's source code and most importantly How They Are Thinking!
Be careful though not to change the functionality of the code you are tarting up. At a minimum:
1. Always provide a module banner (comment block) describing the source file e.g source file name, author, date, desription, project
2. Always provide a function banner describing the function. e.g. function name, description, input and output parameters
Perdabo suggests looking at fuctions to understand how the program is constructed. Another method at looking at a program which might be a bit more immediate when fixing faults, is to look at a variable in the program and see what happens to it. Just pick on the variable you are interested in an use the editor to search for the name.
Although this may seem old fashioned now, some people, still prefer to print out a program to paper and read it and understand it away from the computer. This method does allow you to write notes against the code which may not be suitable for commenting. The print out can also be used as a basis for a peer review meeting where comments or critiques of the code can be written on the listing.
Hope this helps.
MBB