One tool I haven't been able to find that I feel would be super helpful in the IDE is to show where code is covered in tests, like contexts when using python's `coverage`. Does anything like this exist? The benefits are two-fold: they help show me how the methods are supposed to be used, and also guide me on how and where I should test my fix or feature.
Ask HN: How do you search large codebases before adding a feature or fixing bug?
71–80 of 87 posts
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#72What if any frameworks and libraries is it using? Try to identify particularly core frameworks that tend to dictate the whole workflow of the application. Many frameworks have standards of file organization and system architecture that can help you get a handle on what goes where. They may not always have been used properly, but it's a start at least. It might even help to set up a small learning project in that framework just to get to know it better. There may also be libraries in use that influence a lot of how the application does whatever it does.
Trace control flows of the application. How does it start? Do any other processes get started in addition to the main application? Learn how to do the workflow you need to modify, or the closest one to it if you're making a new one. Trace how the command to do X first gets into the application (API call? GUI button press? Some kind of messaging system trigger?), and try to follow the code to see what it does and how it does it.
Trace data flows. Where does the application store critical data, and how does that data actually get picked up from there, transformed, and eventually used, to present to the user or get transformed and handed off to some other system or whatever?
Text search of the codebase can be useful. In strongly-typed languages, often IDE tools are better at jumping straight to the code of the actual method being called though. In less typed languages, text search might be better. Or if whoever wrote the thing did a bunch of dynamic trickery, you may need to resort to running the code, in a unit test if it actually exists, or in your test environment, and attaching a debugger or adding a bunch of log statements.
It's always helpful to understand the business logic of what the application is actually trying to do, and the perspective of developers more experienced with it, if any such people are actually available.
Usually you need to do all of the above to actually develop expertise in a new codebase. Sometimes you have to not be afraid to just jump in and try doing stuff, even if it might not be the best way.
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#73also: GraphViz is a great tool and CLI friendly
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#74https://github.com/hound-search/hound#hound
It would be great if someone integrated this with tree-sitter plus something to make the search semantics a bit smarter about usages of X:
https://www.etsy.com/codeascraft/announcing-hound-a-lightnin...
Screenshots:
https://jaxenter.com/hound-go-react-code-search-engine-15008...
Another trick I use for Java: javap all the Enums out of the compiled artifacts; these indicate weird things like "modes" that you can use to start asking questions relevant to the domain. Like "why are there four ways to reprice an invoice" or finding the "types" of fees or w/e in a billing system. (assuming enum classes are used)
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#75Whenever I work on huge codebase (think 1M+ lines of code), I always reach for Russ Cox's codesearch https://github.com/google/codesearch . It requires indexing the codebase first, which takes 15 minutes or so, but after that searches are instant.
I reach for Hound-search[0] (originally Etsy Houndd) that uses Russ Cox's "Regular Expression Matching with a Trigram Index" I had even made self-serve hosting for it but didn't put much effort into monetizing or otherwise promoting it. [0] https://github.com/hound-search/hound
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#76Concatenate all the source code files into a single file, with pathnames inserted between files. Then use Vim to read the concatenation and (regexp) search.
What is the benefit of this approach versus searching the codebase using tools meant for codesearch? Doesn't this fall over for medium and larger codebases? For example, my current org has over a thousand projects in a single monorepo comprising millions of lines of code in a couple of different languages.
I use Vim on a concatenation. It's a simple technique that allows me to search, read, annotate, and understand how everything fits together in a medium sized C++ codebase full of templates (i.e., a pile of garbage).
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#77Earlier quoted context omitted.
> Oh, they're busy? Well I don't really care Because your time is so much more valuable than theirs!
Lol Yeah, I'm at fault for being hyperbolic on the internet. In real life, I'm absolutely considerate of people's time. I just don't hesitate to ask questions early on and give others an "out" if they're strapped for time. It's just that I don't get it into my head that their time is so much more valuable than mine that I can't interrupt them to ask dumb questions.
Not all are that way though, which can be annoying, but i sincerely hope they can recognize a question only comes up because it is needed to understand the subject.
Tight deadlines or production issues should take precedence though, but other than that you really should try your best to help.
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#78I keep a directory with up-to-date clones of all relevant repos. This is separate from my usual working directory. I experimented with git workspaces, but it wasn't worth the trouble, especially since the set of repos I'm working on is not necessarily the same as the ones I keep in my search dir. At the root level I maintain two scripts: clone.sh update.sh clone.sh has one git clone --recursive .. line per repo. When…
git grep is amazing. I almost never need an alternative.
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#79Earlier quoted context omitted.
It really has no issue as long as you have enough RAM and disabled swap. I recently got a fairly decent gaming laptop that I'm supposed to develop on and the 16 GB RAM is constantly full and it's swapping all the time, browser keeps suspending my background tabs, really pain in the ass.
You really do not want to disable swap on Linux. The operating system does not handle out of memory situations well at all if you do. At any rate, I've got 32 GB of ram and I'm operating off an NVMe-drive, I really don't see what the problem is.
Re: Ask HN: How do you search large codebases before adding a feature or fixing bug?
#80https://codesearchguide.org/story/google
https://codesearchguide.org/story/facebook
https://codesearchguide.org/story/brave
https://codesearchguide.org/story/chromium-android
https://codesearchguide.org/story/linux
https://codesearchguide.org/story/yelp
https://codesearchguide.org/story/stripe
The Google one in particular has a great breakdown of how they use code search by use case (examples, exploration, etc.).
And here are a bunch of known code search tools: https://codesearchguide.org/tools
(Disclaimer: I am the Sourcegraph CEO and our core product is code search.)