TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Ask HN: How do you read code?

6 pointsby dsyangover 11 years ago
Given a new project or an unfamiliar codebase, how do you go about reading and understanding the code?

5 comments

chris_vaover 11 years ago
If you have access to a whiteboard...<p>List all of the directories (or classes, for a smaller project), and draw them as boxes on the board.<p>Draw arrows between the boxes based on dependencies in the codebase (helps if you have someone already familiar).<p>... Now start at the bottom of the dependency graph, and browse the code at a medium level.<p>If you are going to be working in this codebase, go back through and browse the code at deeper level, as if you were doing a code review. You can pretty much assume that, every couple lines, there is always something you would change about the code. Make a note of it.<p>At this point, you should have a fairly decent idea of how the code works, and how you would change it.
评论 #6608249 未加载
评论 #6608902 未加载
nutelaover 11 years ago
Well you should always ask someone who has worked with it but lately I had to come up quickly with a phone formatter class. I didn&#x27;t have a clue how it worked, no comments. So I start to rewrite some of it, run it see what happens. Then when I learned what the stuff did I renamed it so it made sense to me. Used real long variable names which were meaningfull not just tmp and temp. Can really recommend it and it was very fast.
评论 #6608926 未加载
zan2434over 11 years ago
I look at what it does, do a quick architecture in my head, then compare it to what I see. This helps me because before I even look at it I have an understanding of how I think it should work rather than an absolutely clean slate.
评论 #6608916 未加载
sharemywinover 11 years ago
if you have a good debugger then start at the beginning and run it line by line. if a section looks understandable skip it.
评论 #6608936 未加载
libovnessover 11 years ago
From left-to-right