Learning a questionable codebase
Posted by robotisland@reddit | learnprogramming | View on Reddit | 6 comments
There's a large codebase that used to work but stopped working a couple of days ago. My job is to fix the issue.
The code was written by a former employee who left the company a few months ago. I reached out to him, and it turns out he wrote the code using ai and doesn't fully understand it.
The code has lots of unnecessary features and extra complexity.
What's the best way to learn a large codebase, especially when it's unnecessarily complex?
How can a large problem like "learn and fix a large codebase" be broken down into more manageable chunks?
Zealousideal-Ebb-355@reddit
Honestly don't try to learn the whole thing first, that's the trap. it worked a few days ago so something changed recently, the whole codebase didn't rot overnight. do a git log since the last known-good date (or bisect if you know a commit that worked) and the regression is usually one diff. the AI-slop complexity is annoying but it's not what broke you, ignore it til the bug's actually fixed.
johnpeters42@reddit
Worst case, the thing that changed is not the code, but the data (setting up a new scenario that not only doesn't work now, but wouldn't have worked in the past either). In that case, you'll need to debug as usual (including "would it be faster to just rewrite the damn thing properly, or at least do so for one chunk at a time").
Zealousideal-Ebb-355@reddit
Yeah, the data ones are the worst because git log shows nothing changed and you burn a day staring at code that's actually fine. when it smells like that I just grab the input that's failing and replay it locally, usually find it in 5 min instead of an afternoon of reading.
universetwisted@reddit
Since it worked a few days ago, check recent commits/config/env changes before assuming the whole codebase is broken.
The temptation is to rewrite everything because it looks bad. I’d resist that until you have the immediate issue fixed and a few tests around it
After that, perhaps ask AI to create a product reference for the codebase, documenting all of the important parts, and review that super well, while gradually learning how it all works
Good_Skirt2459@reddit
Just make a bigger ball of slop.
Really... AI might be helpful here. Try to have it at least draw out system boundaries and/or write documentation. Might not be perfect but better than nothing to get you started.
Might help to slim down the code base while you're at it, removing the unnecessary stuff.
grantrules@reddit
Attach a debugger and use shitloads of breakpoints