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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Ask HN: How do you discover features in unknown code bases?

26 点作者 hvasilev超过 2 年前
I'm realizing that one of the reasons why I don't do a lot of additional hobby programming is because I'm missing a fundamental skillset that I never developed (in a reliable way) over the years. I think I don't know how to discover features that I'm interested in, in code bases that I'm unfamiliar with. Example: In Chromium I want to find the algorithm that is building the DOM. I'm not sure if that is even part of the code base (https://github.com/chromium/chromium) How would you personally approach this problem?

17 条评论

lukasgraf超过 2 年前
Version control can be a big help.<p>Look through closed tickets in the issue tracker, and try to find a change (bugfix or new feature) that <i>must have</i>, given its nature, touched the functionality you&#x27;re looking for. Then try to find the changeset(s) where that ticket&#x27;s change was implemented.<p>With some luck, the changeset will include a modification to the part of the codebase you&#x27;ve been looking for.
sillysaurusx超过 2 年前
I would search WebKit, not chromium. But keep in mind that there’s a difference between “unknown code bases” and “one of the largest and most complex code bases ever created.” You’re asking, essentially, “in the Windows source code, where is the window layout algorithm?”<p>Stuff like that is certainly possible to find. But it requires a lot of time and dedication.<p>I would personally search for job listings for Chromium &#x2F; Firefox, then use that knowledge to find someone who works on it. Then I’d ask them where it is.<p>But only in this specific case. My normal workflow is to build whatever it is I’m looking at, then change things until it breaks. It’s pretty quick to narrow down what I’m looking for at that point.<p>That doesn’t work here because building chrome requires close to a supercomputer.<p>EDIT: Actually, I would try to find a crash log related to the DOM. The stack trace will point you precisely where you’re interested in. Doing that is easier said than done, but I’ve pulled that trick a couple times, so it seems worth mentioning.
评论 #33491321 未加载
评论 #33490662 未加载
tacostakohashi超过 2 年前
As well as poking around in the source code, do not discount non-source based approaches.<p>For example:<p>* Run chromium using strace, ltrace, gdb to see what&#x27;s going on at runtime.<p>* Do some experiments &#x2F; reverse engineering, treating the application &#x2F; source code as a black box. Try different HTML input, inspect the DOM in chrome, possibly automate this process via selenium or something, and discover the runtime behavior of the algorithm that way.<p>The thing to keep in mind is that, for all you know, the DOM building algorithm is split across thousands of source files, or is in fact in some dependency and not in chromium itself, or is split across both. Presumably there is some particular aspect of the DOM building that you are interested in, so experiment with how that works, instead of trying to find &#x2F; understand the entirety of chromium DOM building.
eurasiantiger超过 2 年前
Clone the repository, open it and let my IDE build an index of the codebase, then use ctrl-p and&#x2F;or ”grep -r keyword .”
biggedyb超过 2 年前
Personally I&#x27;ve never needed to unpick a full blown standalone app like Chromium before, I&#x27;ll be using repo code or dropped into some hulking spaghetti massive legacy app that needs a bugfix, but there&#x27;s no-one left at the company that has any idea how it works and the documentation is _lacking_.. but if this helps then good, otherwise, oops, sorry for the pollute.<p>Breakpoint methodology wins for me simple and true.<p>I imagine it like pathfinding the minotaurs maze, you stand at the last place you recognise and can get back to (if that&#x27;s literally the first active line then that&#x27;s fine), and put something there (breakpoint, print statement, log line), run it and check you still know where you are. Then put another down as far forward from that point that you can &#x27;see&#x27;, if that&#x27;s literally one operation step then fine, spin it and check. Breakpoints are easily put down and just as easily cleared back up again. Keep only as many as you need to see which branch you are on.<p>Pretty soon you&#x27;ll have run the damn thing so many of times you&#x27;ll know it&#x27;s bootstrapping and foibles and they will be second nature. You&#x27;ll start seeing how it&#x27;s generally laid out, you&#x27;ll know where the main start up branchings are. When they leap into async or hidden &#x27;rooms&#x27;, log lines are perfect.<p>When the engine of it starts moving in your head, then is the time to start throwing breakpoints, prints or log lines in places that originally were completely unknown but now you have a feeling for. It&#x27;s at this point you&#x27;ll be bloody close to where you want to be.<p>Oh and do future you a favour, at least jot down something as you&#x27;re going through this. I find that this initial torchlighting is remarkably gratifying but if you don&#x27;t make notes in six months time it&#x27;ll be completely gone, and you&#x27;ll have to do between a quarter to a half of this all over again before the lights start lighting on and you remember how it&#x27;s laid out.
maattdd超过 2 年前
It&#x27;s hard. Normally I start with a word that I know is fairly unique to the domain I&#x27;m looking for (in your case maybe &quot;cssselector&quot;). And what you are looking for is in the Blink third party folder.
chimineycricket超过 2 年前
Usually some kind of string search works. If it&#x27;s frontend then search a string that&#x27;s on the feature. If it&#x27;s backend search a string for table name, http error messages, anything like that.
LostRick超过 2 年前
I&#x27;m no expert but currently currently getting into some coding after a bit of a break. Usually there is documentation, but you never know how relevant it still is. For this example with chromium, it looks like each folder has a readme.md, one even links to a dev wiki&#x2F;guide and in there you can find google docs with diagram of the architecture :) For other projects there might be focus on doxygen which sort of collects the comments from the sourcefiles and puts it into for example html witch class trees etc.
rad_gruchalski超过 2 年前
I usually start by finding issues related to the code fragment I’m interested in. Those usually lead to pull requests in the code I’m interested in.
actually_a_dog超过 2 年前
Read the tests.
评论 #33489971 未加载
simonblack超过 2 年前
You have to know what it is that you want to find <i>before</i> you start discovering.<p>My way is to have a project. What that is is unimportant, but it needs to be big enough that you run into roadblocks.<p><i>Now</i> you know what your weak point is, and what you need to learn to overcome that weak point. So now you also know what it is you need to search for in that code-base.
flamesofphx超过 2 年前
Poke, probe, prod... See what changes, till you get a better idea... I mean what else can you do when there no comment&#x2F;documentation and your dealing with something like:<p>function C($a, $b, $ba, %bb, $c, $d = NULL) { &#x2F;&#x2F;insert random garbage with eval statement.. }
charcircuit超过 2 年前
You use code search. For chromium it&#x27;s hosted at <a href="https:&#x2F;&#x2F;source.chromium.org&#x2F;chromium" rel="nofollow">https:&#x2F;&#x2F;source.chromium.org&#x2F;chromium</a>.<p>You can use filters to narrow down the results to the right languages and paths.
nottorp超过 2 年前
Reading and drawing out the structure as you read. Boxes with arrows or whatever.<p>A good source structure tool will save some time but you’re not getting away without doing your own reading anyway.
teeray超过 2 年前
Search for pull requests that fix bugs in the area you’re interested in. They’ll point you towards the responsible sections of the codebase.
iFire超过 2 年前
sourcetrail is still modern. It hasn&#x27;t fully bitorotted.
baq超过 2 年前
ripgrep<p>But to not leave a one word answer, start searching for a feature you know about and look around from where you find it. It might help to add a super small feature yourself - when it finally works, you’ll have some idea of how the code is structured and will be able to infer where other features would live if they were there. (That might take a bit more than one addition ;))<p>In chromium’s case, what you’re trying to do is more like reverse engineering… I’d start with a debugger.
评论 #33490689 未加载