Wednesday, June 01, 2005

Understanding Programs Written By Others

All programmers will at some point find themselves having to depend on other peoples programs for various things

  1. Maintenance
  2. To use as an extension
  3. To use as a starting point

You could find yourself in a situation where somebody else is working on your code.

Believe me, code does not get thrown away that easily.

I have been thinking of ways and means of understanding third party code easily. Here are my first thoughts

If you are the author of new code

  1. Comment it well (its obvious), but revisit your comments and documents you have written
  2. Read the Practice of Programming before you write code
  3. Learn about Literate Programming and try to use it if possible

If you are burdened with somebody else's code

  1. Read the documentation that comes with the code, too bad if it does not come with any documentation. If you do not understand the document, read it several times
  2. Read the test plan document first and see if you understand the test cases
  3. Use a reverse engineering tool like
    • cflow
    • Any commercial tool available
    • codeviz

  4. Get the overall goals of the software - Don't dig into algorithms right away, just understand what the algorithm is trying to achieve
  5. Search on google for understanding the technology and the jargon

6 comments:

H said...

I remember reading a book by Martin Fowler on Refactoring.Refactoring is a structured way of improving the code and it also enhances one's understanding of the code.

Balbir said...

Refactoring is a great technique. It is useful for code maintenance and for organic code.

kattricker said...

I like the way Javadoc makes it simple for a developer to insert code documentation. The reluctance to document is definitely the extra effort and anything that makes it easier is a developer's delite!

Balbir said...

Yes, I found the following tools useful

1. Doxygen
2. Javadoc
3. Web/Cweb/Nweb, etc

But, if the developer decides not to document the code, we are in soup. Remember good comments can also suffice.

Doxygen can do some kind of reverse engineering, but I am not sure about Javadoc.

Gops said...

Actually, doxygen is more powerful than javadoc as it actually indexes the source code with comments, so you can actually browse code while reading the comments. I love it - it is easy, and works well with all styles of comments.

Balbir said...

Thats really cool! I must start insisting on documentation with code in the future, lets see how much I can impose.

Ranking and Unranking permutations

I've been a big fan of Skiena's Algorithm Design Manual , I recently found my first edition of the book (although I own the third ed...