I've been working in a new codebase recently, and I've been struggling to navigate code. I don't think this code is organized particularly poorly, but I still find myself jumping around and having quite a few files/tabs open trying to follow the thread. In this case some of this code is object oriented and so there's lots of jumping between class and base classes (often multiple base classes deep...) to see where anything happens. I've used VIM marks in the past, I'm trying a bookmarking extension for VS Code, and sometimes I open multiple files in splits to keep things "in context", but I still feel like these are all less than ideal and it's very easy if I step away from my computer for a few minutes for it all to leak out of my brain and then I spend the next 30 minutes trying to get it all back before I can work on the problem.Looking for any tips you all might have for making this easier.
dschuessler|3 years ago
F12: Go to definition
Shift+F12: Go to usages
Ctrl+-: Go back
Ctrl+Shift+-: Go forward
Once you get used to it, it's as easy as browsing the web.
Since I started using VSCode I did not have to work with codebases that were complex enough to make these features valuable but some VSCode language extensions support tree views of call hierarchies and type hierarchies. Here's the documentation for the Java extension.
https://code.visualstudio.com/docs/java/java-editing#_call-h...
https://code.visualstudio.com/docs/java/java-editing#_type-h...
You can set keybindings for them too.
Davertron|3 years ago
Sometimes I do this by just adding a comment, and now that file will at least show up in version control as changed and I can get back to it if I need to, but that's also a little bit janky and I have to be careful I don't leave that cruft around on accident when I commit.
I'm trying out a bookmark extension in VS code and we'll see how it goes, I'm already a little bit annoyed by it in that it doesn't seem to let me organize the bookmarks in any way, so it might be somewhat useful for temporary spelunking, but I won't for example be able to save these bookmarks to refer to them later, which seems like it could be useful.
Sourcegraph has this concept of "Notebooks" which allows you to add files and intermix markdown, which feels like a pretty cool idea, and if I'm just reading code in Sourcegraph it's great, but when I'm in my code editor and making changes I don't want to bounce over to another tool. Maybe it's as simple as keeping some sort of Markdown file open that I write into and then add links to file line numbers as I go, I haven't tried that but I suppose it wouldn't be the worst, and allows me to organize the links in any fashion I see fit.
bluefirebrand|3 years ago
caeril|3 years ago
What version of VScode are you using?
rahimnathwani|3 years ago
BlackFly|3 years ago
Most code (especially legacy code) has more branches than typically matter: the majority of branches is error handling or special cases and can be ignored when investigating core functionality. Executing the happy path test case for the functionality I want to extend or bug fix and then stepping through the code with a debugger or manually is my usual mode.
I use IntelliJ myself. Being able to step through with a debugger can be a huge help to show actual implementations used in polymorphic code but few test suites are sophisticated enough to guarantee the possibility. Sometimes I will refactor code simultaneously in order to make it more comprehensible; that obviously requires some tests and experience but if you have the tests take the time to gain the experience and otherwise write the tests! Especially BDD style tests, the kind that survive refactoring.
rpigab|3 years ago
Davertron|3 years ago
Edit: Oh and I would normally use the debugger A LOT to trace through the code and understand the call stack and params, but another crappy thing about this project is that it generates a massive JS bundle and it crashes the app I'm testing if I try to put debugger statements in...JS ftw
jdorfman|3 years ago
jjk166|3 years ago
nameless912|3 years ago
- <spc>gd = go to definition
- <spc>gr = open a hovering window filled with references to symbol
This is enough to get through every codebase I've yet encountered (Go, Typescript, Python, Java, C++). I also like to use <C-I> and <C-O> in vim which allows you to jump between the most recently viewed locations.
For keeping context, I just write everything down! Either in a scratch file or on a digital notetaking app on my iPad.
stratosmacker|3 years ago
swah|3 years ago
Davertron|3 years ago
c7DJTLrn|3 years ago
I should probably use an IDE but I just don't like them. Sublime is insanely fast and lightweight. I don't want to wait for anything to happen and I find my current workflow allows me to navigate codebases quickly anyway.
livinglist|3 years ago
Davertron|3 years ago
kejaed|3 years ago
johncoltrane|3 years ago
unknown|3 years ago
[deleted]
badpun|3 years ago
i_have_an_idea|3 years ago
In the old days when I did more Java dev, I used Eclipse to view where things are defined and find usages.
factorialboy|3 years ago
Otherwise, searches for file names and contextual links, usages etc.
_smmt|3 years ago
dswilkerson|3 years ago
run strace or ltrace on it;
grep: works better with editor assistance, such as emacs M-x grep;
write documentation for it;
factor out parts of it;
fifteenth|3 years ago
livueta|3 years ago
opengrok is nice if you want code search and navigation in a web interface
aprdm|3 years ago
Take some rough notes on a google doc / gedit so that I don't forget paths that I've explored previously
mickotron|3 years ago
responsible|3 years ago
[deleted]