Understanding code you didn't write
How to read a specific function and figure out what it does
⏱ Est. ~5 min
01 · Read
Last lesson you learned how to get the big picture of a codebase. Now let's zoom in. How do you read a specific function and understand what it does?
This is a skill you'll use every single day as an engineer. You'll open a file, see a function someone else wrote, and need to figure out what it does, how it works, and whether it has a bug.
The good news: code is written in a structured, logical way. Once you know what to look for, reading a function is almost like reading a recipe.
02 · Read
Here's a systematic approach to reading any function you come across. Walk these steps in order, and even the most confusing function will start to make sense.
Key points
- Read the function name — it usually describes what it does
- Read the parameters — what input does it expect?
- Read the return value — what does it output?
- Follow the logic line by line
- Use Claude: "explain what this function does in simple words"
03 · Code example
Read this function and try to figure out what it does before looking at the explanation. Use the steps above: name, parameters, return value, then follow the logic.
Mystery function
function processItems(items, threshold) {
const filtered = items.filter(item => item.price > threshold);
const sorted = filtered.sort((a, b) => b.price - a.price);
return sorted.slice(0, 5);
}
This function takes a list of items and a price threshold, filters out anything below the threshold, sorts by price (highest first), and returns the top 5. Names like 'filter', 'sort', and 'slice' are your clues. Without comments, the code itself tells you what it does — if you know how to read it.
04 · Prompt template
When you're stuck on a function, use Claude to confirm your understanding. Replace the placeholders with your actual file and interpretation.
Explain what the processItems function in {{filename}} does. I think it's {{your_understanding}} — is that right?05 · Fill in the blank
When reading a function, the three things that tell you the most are the name, _____, and the return value.
06 · Quiz
When reading an unfamiliar function, what should you look at first?
- The comments on the function
- The last line of the function
- The variables inside the function
- The function name and parameters
Other lessons in this chapter
⚠ The full interactive experience needs JavaScript. Please enable it and reload.
※ This is an independent Traditional Chinese teaching project — not an official Anthropic product. Claude™ is a trademark of Anthropic, PBC.