Question


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,

Was it helpful?

Solution

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.

OTHER TIPS

Use Source Control before you touch anything!

  • 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.

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

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.

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...

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.

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.

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.

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.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top