Code reading is an important part of a programmer's life because we usually work in groups and have to maintain, complete or contribute to the other developer's codes. From that point of view, code reading is inevitable. Our performance criteria is not only fast reading or interpreting. But also understanding and interpreting the code correctly is very important in our daily work-life. We usually have to deal with several different types of codes such as well documented ones, badly written, undocumented ones, buggy ones and even spaghetti ones. We usually have to deal with each one of them using different techniques and shortly my questions is how do you deal reading those codes, for instance consider dealing with undocumented and badly written codes.
For example I apply some small methods for C/C++ code:
- Find the dependencies of the code and try to figure out the general overview of inter-class or inter-function relationships. Visualise on paper or board if necessary.
- Try to understand the coding conventions they have used and get used to it.
- Understand the general purpose of the functions in a file (figure out why are they populated in that file).
- Start from the main and find the places that you may have to change if necessary.
- Do some small modifications and put print statements in strategic locations to understand what a function or class is doing.
- Use cscope
My question is do you have any these kind of tips, tricks or best practices that you'd like to share?
EDIT: Forgot to ask the question :)
