Discovering unknown systems is something you do from time to time as a programmer. There is something wrong with system X, a system you don’t know, and someone is asking you to fix it. The kind of thing always reminds me of what dilbert calls “the code mocking”.
Every programmer thinks in a different way, or gives different priorities to certain non-functional requirements. Every system evolves over time, requirements change and because of that a system slowly deteriorates. Because of this, and a load of other reasons, discovering unknown systems isn’t always a pleasant experience.
Resources for discovering unknown systems
One of the things I coincidentally found when writing my thesis, is that experienced programmers are much quicker at this task. So there is clearly a trick to discovering unknown systems. What kind of resources can you have available?
- The source code. I’ll get back to this.
- The documentation. Be aware that it might be out of date though. But even out of date documentation can give you an idea as to why this system was built in the first place.
- Maybe it uses some existing framework that you know, or has documentation?
- A programmer with experience with the system. Sometimes a helpful hand can show you in ten minutes what otherwise might take you a day.
- Does it have unit tests? They can be a nice implicit documentation
- Bug tracker. What was the last change that was done, could it be related?
Anyway, assuming that you only have the source code to work with. That doesn’t have to be a bad thing, it’s always the most reliable source of information; assuming you get the correct version of it ;-). The big problem of source code, is that there is usually a lot of it. So, what do you do with it?
- Run it.
- Browse and explore through your editor.
- Personally I try to find an anchor point. Something that you know happens, like a text that is displayed in the interface or an e-mail being sent. If you’ve found the related source code, validate that this is the spot it happens. Maybe there is duplicated code, and this isn’t the one in use.
- If you want to know how this thing is working, come from two ways. The entry point is always easy to find, follow it until it leads you to your anchor point.
- Sometimes it also helps me to refactor to understand. Renaming variables or methods, moving responsibility, etc., can help you to understand how it works.
- But should you have missed the first point: run it. Experiment. Seriously!
Accept that you cannot understand all of it. Try to understand the flow. Do not fall down the rabbit hole. Restrict yourself to the most important part to understand.
The fact remains that every system is different. So I wish you the best with the next system you have to discover! If you have awesome strategies for discovering unknown systems that work for you, let me know in the comments! 🙂