|
|
|
Ask HN: How to start learning large 20 year old code base?
|
|
12 points
by Jiig
2372 days ago
|
|
I've been tasked to try and learn how some very old C++ code base (30k plus lines) at my job, I've heard that its originally from the late 90s and has been updated periodically, since it preforms some very crucial processing. The code is commented fairly well but is missing any sort of top-level architecture documentation or explanation. I've started by just following the flow, but am getting very very lost. Are there any tips you have to help me wrap my head around this? |
|
But as some general advice.
1. Find all the inputs, map their usage/affect through the code. That will help you understand what happens when an input changes.
2. Find all the outputs, do the same as #1. Now you understand with what inputs the expected outputs.
3. Trace through the calls with a given input and do a function & class map, that'll help you see how the code interacts.
Where this gets harder is if the code is multi-threaded, or if it is a huge monolith where there are lots of places to start. In the case of threads, document each thread and the functionality it produces and which inputs are shared, accessed or needed and what outputs come out. Also check the timing against other dependencies. In the case of GUI monolith type application, pick a piece of functionality, as an example, pick login, or app startup and just trace all what happens, and just do this for a bunch of different smaller pieces of functionality until you understand how the code is put together.
As a consultant I used to walk into weird shit all the time, and whether it is I just have a knack for it, or it is my process (basics described above), I can learn code bases quickly and be productive very rapidly. Things that make it harder are lots of DI, especially when it is totally unnecessary for the problem, third party dependencies you can't access and aren't well documented, multi-threading or micro-services where they are not done well and there are lots of interdependencies. Also event systems that are poorly architected can make debugging issues and understanding flow super hard, so I have other methods I use for systems like that, but it basically follows the same pattern above.
The sure fire way to get lost fast is to try and map it all out at once. You have to pick small pieces of functionality, map them, and build it out from there.