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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: Ways for reading open source code bases?

10 点作者 furtivefelon超过 15 年前
Hi all,<p>Can any suggest a good way of understanding a largish code base (thousands of lines)? Is there any tools to help you visualize/understand a code base? In particular, i'm looking for tools for javascript/ruby/python code bases. Thank you very much!

9 条评论

patio11超过 15 年前
Once upon a time, a client of the day job dropped a substantial Perl codebase on our desk and said "Tell us what this does." My boss gave me the job, and expected me to actually READ all the code, but given that I had no desire to read through 100 kloc of Perl code commented only in Japanese, I went for visualization instead:<p>1) Inspect several files for commonalities. Thankfully, the author was obsessive compulsive about coding standards.<p>2) Write a parser for the Perl they used. Use it to glean what pages of the site were connected to each other and what the flow control was like. (a -&#62; b, b -&#62; c, b -&#62; d, etc)<p>3) Plot that on a graph (all hard work already done for me: <a href="http://rgl.rubyforge.org/rgl/index.html" rel="nofollow">http://rgl.rubyforge.org/rgl/index.html</a> )<p>4) Visually inspect the graph to learn non-obvious things about the codebase like "Oh, there is an English language version of the site embedded in here. Isn't that TOTALLY UNDOCUMENTED." Do a bit more code to chop the graph into subgraphs by related functionality (signup flow, admin functions, etc etc).<p>5) Spit out all the code into HTML pages with appropriate autogenerated navigation, inline flow control graphs, and syntax highlighting. Do a bit of quality control, add in some comments about notable things I had learned, burn on CD and hand to customer.<p>6) Charge customer $X0,000 for the CD. The customer was overjoyed they got it done so cheaply. (Did I mention <i>100 kloc of Perl</i>?)
评论 #980774 未加载
nostrademons超过 15 年前
Google Code Search:<p><a href="http://www.google.com/codesearch" rel="nofollow">http://www.google.com/codesearch</a><p>I use it for working my way around Google's codebase, which is a few orders of magnitude bigger than that.<p>Also, there's no substitute for getting your hands dirty and diving into the code. You don't really understand something until you've changed it a few times. Grab a couple of low-priority bugs and write some patches for them; you'll learn far more than if you just sit down and study things.
gtani超过 15 年前
ruby:<p><a href="http://eigenclass.org/hiki/rcodetools" rel="nofollow">http://eigenclass.org/hiki/rcodetools</a><p><a href="http://railroad.rubyforge.org/" rel="nofollow">http://railroad.rubyforge.org/</a><p><a href="http://www.pathf.com/blogs/2008/12/read-the-source-luke-a-readers-guide-to-the-rails-source/" rel="nofollow">http://www.pathf.com/blogs/2008/12/read-the-source-luke-a-re...</a><p><a href="http://stackoverflow.com/questions/37105/how-do-you-actually-read-source-code" rel="nofollow">http://stackoverflow.com/questions/37105/how-do-you-actually...</a><p>---------------------------<p>(you'll see lots of questions on stackoverflow: navigate/inspect/read source repo's)<p><a href="http://stackoverflow.com/questions/1623906/programmatically-inspect-net-code" rel="nofollow">http://stackoverflow.com/questions/1623906/programmatically-...</a><p><a href="http://stackoverflow.com/questions/935516/how-does-macos-developer-navigate-large-code-base" rel="nofollow">http://stackoverflow.com/questions/935516/how-does-macos-dev...</a><p>python:<p><a href="http://code.activestate.com/recipes/213898/" rel="nofollow">http://code.activestate.com/recipes/213898/</a><p><a href="http://stackoverflow.com/questions/1568544/given-a-python-class-how-can-i-inspect-and-find-the-place-in-my-code-where-it-is" rel="nofollow">http://stackoverflow.com/questions/1568544/given-a-python-cl...</a><p>emacs, vim, ctags, etags,<p><a href="http://stackoverflow.com/questions/1220456/navigating-effectively-through-source-code-in-linux" rel="nofollow">http://stackoverflow.com/questions/1220456/navigating-effect...</a>
rajasaur超过 15 年前
Itd be good to get a debugger, connect it to the process and run through the code. You will find a pattern emerging when playing with the application, say, for different clicks of a webapp. After a few days, you will know how the flow works.<p>That said, Ive been more successful looking at the forums of an open source project, figure out what problems folks have and trying to solve them. You will be amazed to see how much you can learn about the code base and undocumented features solving those problems.
tptacek超过 15 年前
Is it a web app? Open up Firebug, look for interesting URLs, and grep for segments of the URL. Find the function that implements it, read bottom-up.
cmars232超过 15 年前
I used to use pdb.set_trace() liberally to poke around at the internals of Django to figure out what it was doing in undocumented places.
评论 #980809 未加载
ssamuli超过 15 年前
I guess you could also take a look at a tool called "LXR Cross Referencer" at <a href="http://sourceforge.net/projects/lxr/" rel="nofollow">http://sourceforge.net/projects/lxr/</a>. Page <a href="http://fxr.watson.org" rel="nofollow">http://fxr.watson.org</a> includes LXR-generated cross references for multiple operating systems.
xenoterracide超过 15 年前
Maybe try this book? <a href="http://www.amazon.com/Code-Reading-Open-Source-Perspective/dp/0201799405" rel="nofollow">http://www.amazon.com/Code-Reading-Open-Source-Perspective/d...</a> I'm not sure how good it is.
gte910h超过 15 年前
Doxygen is great if it understands your language in question
评论 #980868 未加载