Live data from Hacker News

Ask HN: Working with large code base for the first time

news.ycombinator.com

21–30 of 90 posts

Re: Ask HN: Working with large code base for the first time

#21
I like to trace down things in order.

For example, let say I'm working on an ecommerce system and I try to understand what happens when a buyer adds an item to its cart. I'm going to put logs / debugger's prompts on the important steps of that operation. Next to those, add a comment that describes why this step is important. The important thing is to label the comment with incrementing numbers. Those numbers allow me to keep track of the order of execution.

Finally, commit this to a dummy branch and share it with your co-workers if both of you are new to this code base.

That's one of the first thing I do when I jump in a new codebase. Pick something that interests you, and log the whole operation.

Re: Ask HN: Working with large code base for the first time

#22
Debugger is your friend :)

Start by adding breakpoints for some key actions of the app. Then step through the flows with the debugger. First pass you can just step over functions to get the high-level idea. In subsequent passes, you can step into functions that seem important. Rinse and repeat until you understand those actions well. Then move on to other areas in the app.

This works because you can see the actual end-to-end execution flow (not always clear from reading code), inspect runtime data (impossible by reading code) and even change the runtime data (variables, DOM) to validate assumptions about how the code works.

Re: Ask HN: Working with large code base for the first time

#26
If the project you are working on has enough time to burn, and the codebase has no (or near to) unit tests, add them.

Find large utilities that are not coupled with a particular part of the application, and put them under heavy testing. Do not fix any failing test before having completed the test suite.

If you have access to other developers that know the codebase, review the tests with them, and fix failing tests together.

Do the same for the frontend / interface code, but do not go for unit testing imho, go for visual regression testing.

And the end of the process you will have a very large knowledge of the codebase, and you will have improved it at the same time.

Re: Ask HN: Working with large code base for the first time

#28
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

#29
post #26

If the project you are working on has enough time to burn, and the codebase has no (or near to) unit tests, add them. Find large utilities that are not coupled with a particular part of the application, and put them under heavy testing. Do not fix any failing test before having completed the test suite. If you have access to other developers that know the codebase, review the tests with them, and fix failing tests to…

How are you supposed to write tests for code if you don't understand what it does/is supposed to do?

Re: Ask HN: Working with large code base for the first time

#30
I like sourcetrail (https://www.sourcetrail.com/). Sadly, in my latest position I have a Mac and I cannot get it to work on a Java project, as it complains that it cannot find a JRE at the $JAVA_HOME path that I specify (which works for all the other projects, including IntelliJ).

Maybe between Christmas and New Year I might have some time to figure out what is wrong.

Post reply on HN