Take the 2-minute tour ×
Programmers Stack Exchange is a question and answer site for professional programmers interested in conceptual questions about software development. It's 100% free, no registration required.

Concretely I am looking at this 2000 line file of what I will pretty arbitrarily call "mediocre" code.

  • It's not well-commented
  • variable names and function names seem consistently intelligent
  • functions are not well-documented
  • functions are good length

In short: its lines and small structures are readable, but it's impossible to infer architecture or design at a glance. Most code I've worked on can be described thusly, to be fair.

So I need to understand this. And work on it. This is an important skill in software development I'm still weak at, and it's extremely important when working in a nascent system.

So my question is, when encountering foreign code like this that I am employing as client code but now need to understand and modify, what is a quick strategy for having a good understanding?

share|improve this question

marked as duplicate by gnat, Kilian Foth, ChrisF May 25 '13 at 15:23

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

2 Answers 2

I would suggest a top-down approach:

  1. Investigate the build system, including the versioning system, make sure you are not looking at "experimental" branch.

  2. Investigate the overall structure of the code.

  3. Investigate the structure, the test system uses and use the implemented tests to help you understand the code itself.

  4. Investigate each module and ascertain its purpose and document it.

  5. Now you should be able to pinpoint the module which needs changing.

share|improve this answer

Does the code have tests? (there weren't any in that link). If it does that's a great place to start as the tests should tell you the expected behavior of each module.

If it doesn't then write some. Make an educated guess about a function or group of functions and how it performs then write a test to verify if it works as you expect. When your ready to move on to changing the code you will have a set of tests which should help you modify the code without introducing new bugs,

share|improve this answer

Not the answer you're looking for? Browse other questions tagged or ask your own question.