Confusing legacy codebase, totally stuck, no one can help, what do I do?
I'm tasked with a complicated bug fix within a massive legacy codebase that is dependency hell with undocumented spaghetti code. I've been debugging an issue for a few days and have absolutely no idea what to do next. I don't understand the code and no one else does either. I asked my lead what to do and he said to set breakpoints and read the code. I asked where. He said doesn't know.
I've been systematically debugging the issue using every technique I could find on Stack Overflow and books like Code Complete/Debugging. Logs doesn't indicate any useful information. There are no error messages or exceptions. There are no unit tests. All the domain experts I could possibly ask have left. Basically there's no one to help, reading the code and debugging isn't giving me any meaningful data points. I have a general idea what's wrong and where it's happening but my mental model of the application is still weak and things just aren't clicking. I'm super frustrated and feel stuck. I'm also in the middle of a job search and feel like a totally incompetent dev who deserves to rot here for life.
TC: 95k. YOE: 2
comments
With that much technical debt, it only gets worse from here onward.
I was once asked to review a bug fix to the worst legacy code I’ve ever seen. There were goto statements all over. Dozens of bugs had been entered against it for over a decade. I rejected the fix, because no one could say with certainty that there were no other bugs. So I decided to spend a day writing down all the code paths and developing an idea of what was supposed to happen. At that point, I threw the original code in the trash and rewrote a critical function from scratch in a clear and concise way. The next year I was on the project, there was never again an issue. Moral of the story: sometimes the second step should be to throw some part of the old code in the garbage and start from scratch. (The first step being understanding the task at hand.)
Given you have only 2 years of experience I doubt that. No matter what if you are stuck always and always ask for help!
If your lead is not helping escalate to your manager. It's his job to help!
Also you can chk the history of file for write and reach out to guys who would have worked on it.
Whoever wrote this system with no tests is incompetent.
Here are few tips ( most of them were already mentioned in other posts)
- understand higher level purpose of the code/class
- draw out the flow on paper
- Draw Class diagram using ide to see dependencies
- step through the code
- keep writing comments for the parts of code which you have understood
- add more logging
- don’t worry about solving the bug till you can understand the code
- only after above steps - try to reproduce the issue
Forgot to mention, step away from the code and take a walk :)
Other comments above are very insightful. Just want to add that: seek for help from an experienced engineer. He/she will help u learn much faster
If you can't even find any function in which the wrong state happens or what the bug state is, contact previous employees and offer them bribes...