Hacker News new | ask | show | jobs
by guessmyname 1641 days ago
1. Get confortable using “grep” [1], or better, “ripgrep” [2], which is quite faster than the former. They are both available in Linux, macOS, and Windows via WSL.

2. If the project uses a version control system (Git, Mercurial, Subversion, etc.) then take a look at the most recent additions, modifications, and/or deletions in the version control log (git-log, or whatever you want to call it). Sometimes, the most relevant files in a project are the ones people modify the most… obviously, ignore files associated to third-party dependencies (vendor, node_modules, that kind of stuff).

3. Install a Language Server Protocol (LSP) server [3] with support for the programming language(s) that you are going to use. Configure your favourite code editor to take advantage of as many LSP features as possible, with enphasis on “Jump To Definition” and “Find References” [4].

Tell us what programming language(s) is the project written in to give you more suggestions.

[1] https://en.wikipedia.org/wiki/Grep

[2] https://github.com/BurntSushi/ripgrep

[3] https://microsoft.github.io/language-server-protocol/impleme...

[4] https://langserver.org/

8 comments

2 and 3 are great points, but honestly - and especially if you're working in multiple repos, or multiple subdirectories in a monorepo - VS code's folder search is better than grep. It'll find you the exact place in the file, and a click will take you there, nice and easy. I've more or less forgotten the quirks/flags of grep, because I haven't needed to use it in a while.
VSCode uses ripgrep under the hood [1]

[1] https://github.com/microsoft/vscode-ripgrep

Almost the same can be achieved in vim even without plugins

    :tabnew | r ! shopt -o globstar && grep -sn STRING **
This opens a new tab with the grepped output. I simply navigate to the line so my cursor is on the filename, then

    C-w gf
That's [Ctrl-W] followed by [g] and [f]

And just like that, the file is open in yet another tab. The best part? Since the grep output is just another vim buffer, I can search it as well, just like any other buffer.

And yes, ofc the above can be put into a custom command, just by putting this in the .vimrc:

    command -nargs=1 Gr :tabnew | r !  shopt -s globstar && grep -sn <args> **
Then the whole thing can be used like

    :Gr STRING
What if I told you VS code search is ripgrep? Pretty much every coding focused editor has built-in ability to view grep results, then click on the result to jump to the file location. It's 1980's UI technology.
You can also use `git grep` if you're using git, and I'm sure analogues exist for the other VCSs.
+1 for git grep.
To get a sorted list of the most touched java files for example you can run

git log --name-status --pretty=format: | sed 's!.*/!!' | grep java | cut --fields=2- | sort | uniq --count | sort --numeric-sort --reverse

I should add `tig` for navigating git commit history. Very useful sometimes when working with many people on a git repo
Tangential wish - I'd love it if someone figured out a good/generally working way of jumping to definition/references through a URL.

E.g. from `axios.get(`/users/${currentUserId}`) in frontend code jump to `class UserSingleView: def get(self, user_id):` in the backend, and vice versa.

As someone who has worked for years on a UI consuming such information: it's bloody difficult. Each language has its own weirdnesses, you almost always have to build the code to figure out the cross references, and what's correct to the compiler is often non-intuitive to the user. Prime example: C++ code mixing macros and templates. There isn't even a good definition of what the definition is!
I probably do underestimate its difficulty, but certainly appreciate it's bloody difficult. Hence I'd love someone else to do it! I don't have the appetite for it, but it would be fantastic to use.
That is such an annoying thing in codebases. It's the same issue the other way around, I want to see all places in frontend that calls /v1/resource but then some people go and abstract the url into multiple variables.

If it was up to me the constant part of the relative url would never be abstracted away in the codebase. Just a simple grep would instantly get you everything you are looking for.

For IDEs, CTRL+SHIFT+F can be a good replacement for grep. There are similar shortcuts for Jump to Definition and stuff without installation needed.
myself am partial to silver searcher (brew install ag)
ripgrep is a faster and newer alternative with many ergonomic improvements.

The lineage is grep (C, 1973) -> ack (Perl, ~2006) -> ag (C, ~2011) -> rg (Rust, ~2016)

Ack inspired a wave of tool rewrites to accommodate better interfaces and usability.

> Get confortable using “grep” [1], or better, “ripgrep” [2]

And as part of getting comfortable, the -A and -C options are particularly useful.