views:

343

answers:

5

I am a fresh college grad student that just started my job. In my ramp up period, I need to learn a lot of product code. There are some design docs but they do not help much.

Can you provide some general techniques to browse and understand huge product code (specifically C++)?

+4  A: 

Run it through doxygen. This will generate html documentation which will be helpful even if the code does not have proper doxygen-style comments.

Another good advice is to look through the unit tests, if there are any. If there are no unit tests, a good way to understand the code is to write your own unit tests. The effort to do this will pay for itself many times over.

Dima
+6  A: 

Use every method available to you (in no particular priority):

  1. Use the product itself and understand what it does
  2. Talk to the devs that maintained it or have worked with it previously
  3. Debug through it and see how data flows and how classes interact ("when I click this button, what exactly happens, who is responsible?")
  4. Look at architecture, UML, or class diagrams
  5. One of my favorites: create your own diagrams of class hierarchies, class interactions, general control flow, high-level components, process/DLL interactions, object lifetimes and management
  6. If they're not totally out-of-date, read the dev/test/user specs (goes well with #1)
  7. Read the documentation on it

Most of all: be tenacious and persistent. If you don't put in the work, don't expect to understand it. If you don't understand something, dig and dig until you do. Software is not magic, it's just hard work :)

Chris Schmich
Nice list. However, I think you do have them in the order of priority. Most of the time on a large, old project, any documentation is worthless.
aaaa bbbb
I would add that if you do work on step (5), share your diagrams with the team. Most teams (mine included) welcome the contribution. Your effort can help supplement the already lacking documentation set.
D.Shawley
A: 

This is obviously a pretty common question, and it's similar to this one (and the questions related to it): http://stackoverflow.com/questions/3586410/how-to-understand-the-design-and-code-flow-of-any-product-quickly

Dig through some of those answers / comments, for starters. Else, we'll just end up repeating them. :)

djacobson
+4  A: 

Some people will tell you to start with the data structures, but in a large system even that's not terribly helpful much of the time. I can think of four major points:

  • Take your time. Often, it's more like a whole series of gestalt shifts than it is a single, linear, gradual understanding. So be patient.

  • No matter how big it is, you should be able to put a breakpoint in and walk it in a debugger. Even in a large, complicated, multi-threaded system, you should be able walk through and see what's happening.

  • Ask for bugs, and start fixing them, no matter how crazy they seem. It's akin to dropping yourself into a foreign country; you'll pickup the language eventually.

  • Find a mentor. A jungle guide is invaluable.

jrtipton
+1: Fixing bugs is a great forcing function to learn a codebase. Unless the bug is really trivial, you'll have to learn some part of the code to be able to fix it.
Chris Schmich
Bug fixes are what I always ask to do if I am tasked with learning any new software. That way you not only understand what it is doing, but how (and sometimes better than your colleagues if they couldn't figure the bug out).
Austyn Mahoney
A: 

I think there have been a few good responses already. My 2c worth...

Not sure what you class as huge (10 KLOC, 1000 KLOC, 10000 KLOC, etc), but one would hope that this is broken down in some way and is not a monolithic single program. Perhaps your management has some guidance on which 'module(s)' you are most likely to be spending time in at the moment. Hopefully this can help break down the problem scope.

Firstly, before you try to understand the code try to understand the product. What does it do? Then how does it do it? What does it interact with? Then how does it interact? etc...

When getting to the code try to understand the high level design and philosophy first, and work on the breadth before the depth. I agree with some of the above re fixing some bugs, but I also strongly suggest you continue to get a handle on the high level even if you need to get into the details to fix some bugs.

I also agree with the above in terms of generating some diagrams for yourself if you can't find any already in existence. And then share them, perhaps a team/product wiki? I'm curious as to why the existing doco does not help very much. Typically this is because this type of doco was generated from the early concepts and the product no longer bears any similarity, but if this is not the case then what can you contribute to this issue. One assumes that where you are today someone else will be in short enough order, and you are in an ideal position to know what essential doco is missing!

If the product is actually 'huge' then you have to accept that you will never be able to hold all of it in your head, so the best thing you can do is be familiar enough to know where to start looking (comes back to understanding the product, and approaching code breadth first).

Michael