Reading Code: Know what you're looking for
In the last week or so before Christmas I got the chance to spend some time pairing with my colleague Alex Harin while trying to understand how an existing application which we were investigating was written.
We knew from watching a demo of the application that the user was able to send some processing off to be done in the background and that they would be emailed once that had happened.
Our starting point was therefore to work backwards from the labels on the UI and finding which code got executed when the user submitted the task.
My initial approach was to find the entry point and then follow the method calls line by line, slowly building my knowledge of how the application actually worked.
Alex used a much quicker approach whereby he thought about how the code would be designed and then looked for the bit of code which proved his belief.
In this case we knew that the application had a 2 tier architecture and that it didn’t use any middleware which meant that it would more than likely be using the database as a queue to store the tasks to be processed.
Another colleague and I were then able to make use of this approach when looking at another piece of code.
It was being used to do pricing and we knew that there were different algorithms depending on which country you were in, which meant that we needed to look for anything country related to answer our questions.
Effectively we’re looking at the code with a hypothesis in hand and then trying to see whether or not what we see proves or disproves that hypotheses.
I need to practice a bit more but it seems to let you navigate code much more quickly and makes you much less likely to dive down a rabbit hole.
About the author
I'm currently working on short form content at ClickHouse. I publish short 5 minute videos showing how to solve data problems on YouTube @LearnDataWithMark. I previously worked on graph analytics at Neo4j, where I also co-authored the O'Reilly Graph Algorithms Book with Amy Hodler.