Many developers have found themselves in this potentially challenging and frustrating situation: taking over someone else’s code project. Where to begin? In a recent Q & A session on the Programmers Stack Exchange, this question was explored: “What tools and techniques do you use for exploring and learning an unknown code base?” Following are some methods that will hopefully keep the struggling programmer afloat in their pool of unknown code:

Jump in Feet First and Get Swimming!

One group of options suggested by programmer Kramii, encourages you to dive right into the pool of unknown code and get swimming.

“As for the place to start, start with what you do know. I suggest inputs and outputs. You can often get a handle on what these are supposed to be and what they are used for. Follow data through the application and see where it goes and how it is changed.”

– Try to find out what the code is supposed to do, in business terms.

– Read all the documentation that exists and communicate with anyone who might be familiar with the code.

– Step through the code in the debugger and try to break it by making small changes.

– Then, use various methods to clarify the code:

  • Use tools to format the code and add comments to explain what it does and then highlight the use of symbols
  • Change variable names to make them clearer and use current code conventions (using a refactoring tool, to restructure the existing code)

– Get rid of clutter and duplication like code that’s been commented out, meaningless comments, pointless variable initializations and so forth.

– Start to extract functionality into meaningful routines and add tests where possible

– Make other simple improvements where you can

Through these methods, hopefully deciphering the code and its meaning will be clarified.

Normalize your surroundings

Another user from StackExchange, sal, suggests to standardize the code and put it on the same platform for simplification and analysis:

“I like to do the following when I have a really large source file:”

– Copy the whole mess onto the clipboard and paste it into Word or another text editor
– Reduce font size to the minimum viewable and scroll down looking at the patterns in the code

“You would be amazed at how oddly familiar the code looks when you get back to your normal editor.”

Pull out your Programming “Boogie Board” Editing and Development Tools to Keep Afloat in your Unknown Code Pool

StackExchange user JeffV uses these tools to help him swim through another user’s code pool:

– Use a source analysis tool like Source Monitor to determine the various module sizes and complexity metrics, to help identify the areas that are non-trivial.

– Drill through the code top to bottom in Eclipse (good to have an editor that can browse references and so on), to know what’s going on and where in the code base.

– Occasionally, I draw diagrams in Visio to get a better picture of the architecture. This can be helpful for others on the project as well.

Learn the Size and Shape of the Pool to Swim Effectively

Finally, from another programmer, JB King, know the expectations and parameters of the project stakeholders, in terms of what they are expecting from you:

– Are you putting in new features?

– Are you fixing bugs?

– Are you refactoring code? Are the standards new to you or are they very familiar?

– Are you supposed to be just familiarizing yourself with the code base?

No matter how you choose to stay afloat in your unknown code pool, stay safe and sane in those rough waters by following some of these suggestions.