TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Ask HN: How do you read code?

6 点作者 dsyang超过 11 年前
Given a new project or an unfamiliar codebase, how do you go about reading and understanding the code?

5 条评论

chris_va超过 11 年前
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 未加载
nutela超过 11 年前
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 未加载
zan2434超过 11 年前
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 未加载
sharemywin超过 11 年前
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 未加载
libovness超过 11 年前
From left-to-right