Algorithm how I usually approach foreign code (look down for a terse version of it in pseudo-code).
The best way to start exploring the foreign system is to read its documentation, especially if special developer documentation (developer manual etc.) is available here. Ask the previous developer to send you any documentation he or she has for the system and appoint a meeting with him/her (if this is feasible) in 1-2 weeks.
While preparing for the meeting study the documentation. If there is no documentation than you may have chances to get a copy of original specifications that were used to implement the system (in big companies these are usually prepared by Program/Project Managers and kept longer, than running documentation).
If your IDE (like VS2010 Ultimate or Eclipse with Plug-ins) support creating architecture diagrams, than try those to get an overview of your system. There is a bunch of special software, like JDepend/NDepend, depending upon your system, which can be useful here.
If you don't get any specification, look at unit tests -- this is in fact a part of the specification as well and already written in the form familiar to you.
During the meeting ask the developer to guide you through the system and ask questions to the parts you don't understand. I usually try to put myself in developer's shoes and see if something seems to be implemented in somewhat strange way: just ask, maybe there are implicit requirements or limitations you should be aware of.
And here is the promised succinct version of the text above.
if (Documentation.Exists()) ReadDocumentation();
else {
AskDeveloperIfThereIsDocumentationLyingSomewhereAround();
if (Documentation.Found()) ReadDocumentation();
}
If (Code.IsDocumentedProperly()) {
ExtractCodeDocumentation();
ReadCodeDocumentation();
}
If (IDEOfYourChoice.Supports(ArchitectureDiagramms)) ProduceDiagrammsAndStudyThem();
if (Specification.Exists()) ReadSpecification();
else AskPMIfThereIsDocumentationLyingSomewhereAround();
TryToRunTheSoftwareOnYourOwn();
if (Developer.IsAvailable()) AskToGuideYouShortlyThroughTheCode();
else if (User.Any( user => user.IsCompetent(ThisSystem))) AskUserToGuideYouThroughProgramm();
If (System.HasUnitTests()) {
ReadUnitTests();
RunUniTests();
}