views:

344

answers:

10

Hi all,
I have to do enhancements to an existing C++ project with above 100k lines of code.
My question is How and where to start with such projects ?
The problem increases further if the code is not well documented. Are there any automated tools for studying code flow with large projects?

Thanx,

+14  A: 

Use Source Control before you touch anything!

AraK
Yeah, that's crucial, so +1 even though @nader's answer is even more topical so I upvoted it too;-).
Alex Martelli
+12  A: 

There's a book for you: Working Effectively with Legacy Code

It's not about tools, but about various approaches, processes and techniques you can use to better understand and make changes to the code. It is even written from a mostly C++ perspective.

Nader Shirazie
+1, the state of testing is key, as Feathers, the author of the book you recommend, points out so effectively.
Alex Martelli
+1  A: 

Running Doxygen with the EXTRACT_ALL tag set to document all the relationships in the code base. It's not going to help you with the code flow, but hopefully it will shed some light with regards to the structure and design of the entire application.

Soo Wei Tan
+2  A: 
  • First study the existing interface well.
  • Write tests if they are absent, or expand already written ones.
  • Modify the source code.
  • Run tests to check if the modification somehow breaks the older behaviour.
Alan Haggai Alavi
+1  A: 

If you are able to run the code in a PC, you can try to build a callgraph usually from a profiling output.

Also cross referencing tools like cscope, ctags, lxr, etc. Can help a lot. A

Spending some time reading, building class diagrams or even adding comments to the parts of the code you took long to understand are steps towards getting familiar with the codebase and getting ready to modify/extend it.

piotr
+1  A: 

There is another good book, currently freely available on the net, about object oriented reengineering : http://www.iam.unibe.ch/~scg/OORP/

zim2001
+2  A: 

The book "Code Reading" by Diomidis Spinellis contains lots of advice about how to gain an overview and in-depth knowledge about larger, unknown projects.

Chapter 6 is focuses sonely on that topic (Tacking Large Projects). Also the chapters about tooling (Ch. 9) and architecture (Ch. 8) might contain nice hints for you.

However, the book is about understanding (by reading) the "code". It does not tackle directly the maintenance step.

dmeister
+1  A: 

The first thing you need to do is understand how the code works. Read what documentation there is and then watch the program operate under a debugger. If you watch the main function/loop and then slowly work your way deeper into the program, you can gain a pretty good idea how things are operating. Make sure you write down your findings so others who follow after you have a better position to start from.

Steve Rowe
A: 

A very good austrian programmer once told me that in order to understand a program you first have to understand the data-structures that the program uses.

tr9sh
+2  A: 

First thing I would do is try to find the product's requirements.

It's almost unthinkable that a product of this size would be developed without requirements.

By perusing the requirements, you'll be able to:

  • get a sense of what the product (and hence the code) is at least supposed to be doing
  • see just how well (or poorly) the code actually fulfills those requirements

Otherwise you're just looking at code, trying to divine the intention of the developers...

Dan