Possible Duplicate:Ive inherited 200K lines of spaghetti code  what now? I have been recently handled a giant multithreaded program with no comments and have been asked to understand what it does, and then to improve it (if possible). Are there some techniques which should be followed when we need to understand someone else's code? OR do we straightaway start from the first function call and go on tracking next function calls?C++ (with multi-threading) on Linux
What is the way to understand someone else's giant uncommented spaghetti code?
c++;productivity;linux;code reviews;maintenance
This will depend on the language, but (and I know it's a terribly old fashioned tool) IMHO you cannot beat a simple flow chart for code, with associated data-flow diagram.Pretty much the way one would have designed code from requirements, in days of yore.Start from the whole program, and decompose... Obviously, you'll be doing a separate chart for each (non trivial) function... the detail of each chart depends on the functional complexity.In the case of classes, treat each class as a standalone, self-contained block - from a system viewpoint, each class should (if designed properly) be able to be considered as a black boxDecompose the whole into classes, then classes into data structures and functions, etcModern-fangled tools such as the UML have their place, but for reverse engineering, stick to the basic tools.