News for hackers. Stuff that matters.
Re:Ask HN: Working with large code base for the first time by guessmyname on Wednesday December 22, 2021 @01:47AM (#29646244)
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/

Re:Ask HN: Working with large code base for the first time by gorgonzolachz on Wednesday December 22, 2021 @03:14AM (#29646727)
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.
Re:Ask HN: Working with large code base for the first time by akiselev on Wednesday December 22, 2021 @03:29AM (#29646812)
VSCode uses ripgrep under the hood [1]

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

Re:Ask HN: Working with large code base for the first time by usrbinbash on Wednesday December 22, 2021 @05:49AM (#29647674)
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
Re:Ask HN: Working with large code base for the first time by foobarbaz33 on Wednesday December 22, 2021 @08:50PM (#29657784)
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.
Re:Ask HN: Working with large code base for the first time by kuyan on Wednesday December 22, 2021 @02:34AM (#29646467)
You can also use `git grep` if you're using git, and I'm sure analogues exist for the other VCSs.
Re:Ask HN: Working with large code base for the first time by devoutsalsa on Wednesday December 22, 2021 @02:52AM (#29646575)
+1 for git grep.
Re:Ask HN: Working with large code base for the first time by splittingTimes on Wednesday December 22, 2021 @03:39AM (#29646879)
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

Re:Ask HN: Working with large code base for the first time by Faaak on Wednesday December 22, 2021 @08:10AM (#29648813)
I should add `tig` for navigating git commit history. Very useful sometimes when working with many people on a git repo
Re:Ask HN: Working with large code base for the first time by OJFord on Wednesday December 22, 2021 @04:10AM (#29647086)
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.

Re:Ask HN: Working with large code base for the first time by larsrc on Wednesday December 22, 2021 @05:27AM (#29647542)
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!
Re:Ask HN: Working with large code base for the first time by OJFord on Wednesday December 22, 2021 @12:22PM (#29652290)
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.
Re:Ask HN: Working with large code base for the first time by ui4jd73bdj on Wednesday December 22, 2021 @07:55AM (#29648640)
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.

Re:Ask HN: Working with large code base for the first time by muzani on Wednesday December 22, 2021 @10:13AM (#29650355)
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.
Re:Ask HN: Working with large code base for the first time by Areading314 on Wednesday December 22, 2021 @03:31AM (#29646830)
myself am partial to silver searcher (brew install ag)
Re:Ask HN: Working with large code base for the first time by echelon on Wednesday December 22, 2021 @03:50AM (#29646958)
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.

Re:Ask HN: Working with large code base for the first time by jolmg on Wednesday December 22, 2021 @08:16PM (#29657615)
> Get confortable using “grep” [1], or better, “ripgrep” [2]

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