Live data from Hacker News

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

news.ycombinator.com

21–26 of 26 posts

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

#22

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?” Stuff like that is certainly possible to find. But it requires a lot of time and dedication. I would personally search for job listings for Chromium…

How did you know it was in Webkit or Blink? What was your thought process that lead you to this conclusion? Was it prior knowledge?

I tried to think of a less-unsatisfying answer, but it was just prior knowledge. All the major browsers use Webkit or a fork of WebKit, and WebKit had to be the thing that lays out the DOM since it’s not chrome-specific. (If you were looking for something specific to chrome, it’d probably be a lot harder to find. Or at least for me to find.)

The other comments are good too: try searching the metadata for the code, like git logs, pull requests, etc.

I suppose a new age solution might also be to type “// The DOM layout algorithm:” into Copilot and pray.

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

#23
Personally I've never needed to unpick a full blown standalone app like Chromium before, I'll be using repo code or dropped into some hulking spaghetti massive legacy app that needs a bugfix, but there'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.

Breakpoint methodology wins for me simple and true.

I imagine it like pathfinding the minotaurs maze, you stand at the last place you recognise and can get back to (if that's literally the first active line then that'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 'see', if that'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.

Pretty soon you'll have run the damn thing so many of times you'll know it's bootstrapping and foibles and they will be second nature. You'll start seeing how it's generally laid out, you'll know where the main start up branchings are. When they leap into async or hidden 'rooms', log lines are perfect.

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's at this point you'll be bloody close to where you want to be.

Oh and do future you a favour, at least jot down something as you're going through this. I find that this initial torchlighting is remarkably gratifying but if you don't make notes in six months time it'll be completely gone, and you'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's laid out.

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

#24
Poke, probe, prod... See what changes, till you get a better idea... I mean what else can you do when there no comment/documentation and your dealing with something like:

function C($a, $b, $ba, %bb, $c, $d = NULL) { //insert random garbage with eval statement.. }

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

#25
You have to know what it is that you want to find before you start discovering.

My way is to have a project. What that is is unimportant, but it needs to be big enough that you run into roadblocks.

Now 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.

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

#26

Read the tests.

First you may need to find the appropriate tests, which is essentially the same problem OP describes.

I would say it's a related, but much simpler problem. Often, codebases will have some sort of command (sometimes in a Makefile, or similar) to run the tests, which you can use to track down where the tests live. Failing that, tests are often found in files, functions, and directories containing the string 'test' in their names. Simple use of shell tools can accomplish the task of looking for those things in a semi-automated way.
Post reply on HN