Understanding Unfamiliar Code
Reviewing Pull Requests depended on reading code quickly and accurately. In some rounds that reading is the whole task: you're given a codebase and asked questions about it, with or without a change at the end. Google has piloted a code-comprehension round built around an existing codebase, and parts of many other rounds work the same way, since an interviewer who asks "what happens if this fails?" halfway through a bug task is testing comprehension too. This page covers how to answer those questions correctly and show how you know.
What These Questions Look Like
Comprehension questions come in a few shapes, and each needs a slightly different search. Knowing the shape tells you where to start, so name it to yourself before you open any files.
- Where. "Where are permissions checked for file downloads?" Start from the entry point, the route or command, and follow the call path until you hit the check.
- What happens when. "What does the user see if the payment provider times out?" Find the failure point, then follow the error upward until something catches it.
- Why. "Why does this endpoint return stale data sometimes?" Usually a cache, a race or a read from a replica; look for where the data is stored and where it's read.
- What would break. "What breaks if we rename this field?" Search for every reference, including strings, serializers, migrations and tests.
- Which wins. "If both the config file and an environment variable set the timeout, which is used?" Find the one function where the values meet and read it line by line.
The answer is always somewhere in the code, and the interviewer usually knows exactly which lines. That's what makes these questions gradable, and it's why guessing from function names fails.