Concretely I am looking at this 2000 line file of what I will pretty arbitrarily call “mediocre” code.
- It’s not well-commented
- variable names and function names seem consistently intelligent
- functions are not well-documented
- functions are good length
In short: its lines and small structures are readable, but it’s impossible to infer architecture or design at a glance. Most code I’ve worked on can be described thusly, to be fair.
So I need to understand this. And work on it. This is an important skill in software development I’m still weak at, and it’s extremely important when working in a nascent system.
So my question is, when encountering foreign code like this that I am employing as client code but now need to understand and modify, what is a quick strategy for having a good understanding?
0
Does the code have tests? (there weren’t any in that link). If it does that’s a great place to start as the tests should tell you the expected behavior of each module.
If it doesn’t then write some. Make an educated guess about a function or group of functions and how it performs then write a test to verify if it works as you expect. When your ready to move on to changing the code you will have a set of tests which should help you modify the code without introducing new bugs,
I would suggest a top-down approach:
-
Investigate the build system, including the versioning system, make sure you are not looking at “experimental” branch.
-
Investigate the overall structure of the code.
-
Investigate the structure, the test system uses and use the implemented tests to help you understand the code itself.
-
Investigate each module and ascertain its purpose and document it.
-
Now you should be able to pinpoint the module which needs changing.