boliveira
Welcome to my Social Blog
3y ago
Reading code
boliveira

Reading code is rarely emphasized as much as writing it. However, this imbalance can be harmful because developers spend much more time reading code than writing it, so, getting good at reading code can be a huge force multiplier.

Emphasis is on creating, not maintaining

Most online resources focus only on creating things or writing new code, instead of advocating for reading it. Why?

  • Feature work requires writing code;

  • Productivity is still correlated with writing code;

  • Culture is centered around creating and innovating. Reading is passive;

By focusing your efforts on reading code, you will become better at writing it too.

Step 1: Search for an entry point

When you start reading code, it's a good idea to search for a couple of key areas that act as entry points for a certain flow you want to analyze: a specific class, method, or package. When you've identified these, move to the next step.

Step 2: Always prefer DFS over BFS when reading code!

Essentially, always go as deep as possible after following a thread from a starting point. This allows you to get an "end-to-end" view of a given flow which can increase your understanding. It also gives you a good overview of test coverage across layers and how things are structured.

Step 3: When possible, read the tests, if not, add them

Finally, the last important point to make: having code covered by tests, either unit or integration (preferably both) can greatly increase your understanding by allowing you to focus on atomic pieces of logic and understand the expectations for each of these in isolation. It also helps when refactoring code as it can give you extra assurances that the underlying logic is left unchanged!

By focusing on going in depth-first, you can more easily understand the code as you read it and with practice, this will become easier over time!

0

Atomic Essay

Comments

What will you write today?

Write, publish, get feedback, and become a better writer.

Trusted by 75,000+ writers